code:
dispatch_async( dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{ [serverapi api_getchatlist:self withuserid:[self getuseridfromuserdefaults] withscheduleid:strgroupid withtype:@"group"]; dispatch_async(dispatch_get_main_queue(), ^{ [self performselector:@selector(getchatlist) withobject:nil afterdelay:10]; }); });
i used dispatch global queue call method every 10 seconds.it working fine.the problem global queue keep running in other controllers too.how stop running?any appreciated.
you can keep bool
property,before every call, check property. when want stop, set yes
@property (atomic) bool stop;
function
-(void)getchatlist { if (self.stop) { return; } dispatch_async( dispatch_get_global_queue(dispatch_queue_priority_background, 0), ^{ //do dispatch_async(dispatch_get_main_queue(), ^{ if (!self.stop) { [self performselector:@selector(getchatlist) withobject:nil afterdelay:10]; } }); }); }
Comments
Post a Comment