Hi All,
I have an application in which I am repetitively calling a method in background. I implemented this by following below steps:
1. created a background thread,
2. called the appropriate method on the created thread,
3. called sleep method on the thread, and
4. again called the previously invoked method.
Below is the code which I used:
I have read that NSThread is not the best way to perform background task, and there are other classes provided in cocoa, such as - NSOperationQueue and NSDispatchQueue, which should be preferred over NSThread to perform an asynchronous task. So I am trying to implement the above specified functionality using the alternative classes.
Problem is - though I am able to perform an asynchronous task using these classes, I am unable to perform a repetitive task (as in my case) using these classes.
Can someone throw some light on this and guide me towards the correct direction?
Thanks,
I have an application in which I am repetitively calling a method in background. I implemented this by following below steps:
1. created a background thread,
2. called the appropriate method on the created thread,
3. called sleep method on the thread, and
4. again called the previously invoked method.
Below is the code which I used:
- (void) applicationDidFinishLaunchingNSNotification *)notification
[NSApplication detachDrawingThreadselector(refreshUserIdPassword) toTarget:self withObject:nil];
}
-(void)refreshUserIdPassword
{
[self getAllUserIdsPasswordsContinousely];
[NSThread sleepForTimeInterval:180];
[self refreshUserIdPassword];
}
I have read that NSThread is not the best way to perform background task, and there are other classes provided in cocoa, such as - NSOperationQueue and NSDispatchQueue, which should be preferred over NSThread to perform an asynchronous task. So I am trying to implement the above specified functionality using the alternative classes.
Problem is - though I am able to perform an asynchronous task using these classes, I am unable to perform a repetitive task (as in my case) using these classes.
Can someone throw some light on this and guide me towards the correct direction?
Thanks,
Last edited: