I want to terminate all currently called methods and then simply re-init my current object.
So when the user clicks on say the Start button, I call a bunch of methods…start doing stuff. Then when the user clicks on Cancel, i need to simply stop all running tasks/methods and re-init.
I don’t want the app itself to terminate. So cannot use [NSApp terminate:nil]. I just need all current functions to stop and then i can call [self init];
Thanks in advance.
First, you have to set some flag and disable your user interface until all methods are completed. For example,
self.cancelled = YES.Next, each of your methods should be adjusted to return if that flag is set:
Then, you need a mechanism to track all your methods. Most likely, you will use
NSOperationQueueordispatch_queue_t. Take a look into documentation to find out how to get a notification when the queue becomes empty.Finally, reset the
self.cancelledflag and unblock your user interface.