Reputation: 3143
In my application I need to process an array of Data and send it to server only if internet connectivity is available. I need to perform this task on separate thread so the normal execution of Application is not interrupted.
I have created a class called ProcessQueue
that iterates over the array and sends it to server.
I need to perform this task on ApplicationDidBecomeActive event with a delay of some seconds but on a separate thread.
I tried following but selector just doesn't get called. (I am trying to set breakpoints inside ProcessQueue
class).
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self performSelector:@selector(processTheQueue) withObject:nil afterDelay:5];
dispatch_async( dispatch_get_main_queue(), ^{
});
});
- (void) processTheQueue
{
QueueProcessor *process = [[QueueProcessor alloc] init];
[process processQueue];
}
I have also tried to use performSelector inside the [process processQueue]' method instead of
dispatch_async` but doesn't work.
Upvotes: 0
Views: 241
Reputation: 177
Try this..
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// code to be executed on main thread.If you want to run in another thread, create other queue
[self repeateThreadForSpecificInterval];
});
Upvotes: 1