iphone - suspending dispatch timers from main_queue when it was created on another one -
can suspend gcd timer queue besides 1 it's schedule run on?
i have timer, created on global_queue low priority , when fires, manipulate ui work via main_queue. states in ui, have suspend timer. have switch main_queue low priority queue perform suspend?
dispatch_queue_t lowpriq = dispatch_get_global_queue(dispatch_queue_priority_low, 0); mytimer = dispatch_source_create(dispatch_source_type_timer, 0, 0, lowpriq); dispatch_source_set_timer(mytimer, starttime, // interval, // 15 seconds 2000ull); // configure event handler dispatch_source_set_event_handler(mytimer, ^{ nslog(@"timer fired"); // ui work dispatch_async(dispatch_get_main_queue(), ^ { [self dosomebuttonenabledisable] }); }); dispatch_resume(mytimer); // start timer - (void)dosomebuttonenabledisable { if (someparticularstate) { // turn off timer // should suspend timer on low priority global queue // or valid suspend on main queue? dispatch_queue_t lowpriq = dispatch_get_global_queue(dispatch_queue_priority_low, 0); dispatch_async(lowpriq(), ^ { dispatch_suspend(mytimer); }); } }
yes, it's valid suspend dispatch object queue. if block running when dispatch_suspend() called, block complete execution , subsequent scheduled blocks prevented executing.
Comments
Post a Comment