OS X Cocoa concurrency: how to return control to the UI after a task is launched -
OS X Cocoa concurrency: how to return control to the UI after a task is launched -
i have calculation task take time complete. minutes. maybe several minutes. want launch task button on ui, homecoming ui user can interact other areas while task running.
i modeled code after illustration apple's concurrency programming guide:
// code here initialize c++ objects a, b, c, , d ivars. - (nsoperation*)taskwithdata:(id)data { nsinvocationoperation* theop = [[[nsinvocationoperation alloc] initwithtarget:self selector:@selector(mytaskmethod:) object:nil] autorelease]; homecoming theop; } // method actual work of task. - (void)mytaskmethod:(id)data { // perform task. task(a, b, c, d); }
then phone call mytaskmethod:data
within button's ibaction:
-(void)actionbuttonpushed:(id)sender { nsautoreleasepool* mypool = [nsautoreleasepool alloc] init]; [self mytaskmethod:nil]; [mypool drain]; }
i hoped command homecoming ui, doesn't. don't homecoming ui until mytaskmethod:
finishes business ... same behavior if called task()
straight in ibaction code.
more details: code objective-c++ (.mm), , task(); c++ function.
if it's not obvious, first effort @ using concurrency; need direction, please.
tia, g
update: fixed. had neglected create snoperationqueue, , add together nsoperation queue.
update: fixed. had neglected create snoperationqueue, , add together nsoperation queue.
cocoa concurrency
Comments
Post a Comment