I know dispatch_async can handle thread.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// handle things that takes a long time
dispatch_async(dispatch_get_main_queue(), ^{
// update UI
});
});
But How can I cancel it the thread?
For example:
I have two viewcontrollers- AViewController and BViewController, A->present B, and a button to dismiss B.
I'll do myMethod
in BViewController, the things is I want to dismiss B when exec myMethod
, so I use dispatch_async
, it did dismiss from B to A. but after going back to AViewController, here comes the audio.
How can I stop the myMethod
after dismiss method exec immediately?
- (void)myMethod {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// handles thing A
// play a audio
dispatch_async(dispatch_get_main_queue(), ^{
// update UI
});
});
}