osx - Pumping Cocoa message loop from background thread -
osx - Pumping Cocoa message loop from background thread -
i have cocoa-based command line application programmatically creates nswindow + nsview. uses nexteventmatchingmask loop manually pump event loop , dispatch events. loop called upper level code periodically poll input.
if run on main thread works fine in view receives input events correctly.
if instead move window creation , message loop separate thread nexteventmatchingmask no longer returns events , view doesn't receive input.
i'm aware "main" thread in cocoa app supposed handle events. secondary thread thread needs talk cocoa, utilize "main" thread far cocoa concerned. possible? phone call nsapplicationload thread, , far know first cocoa function called in process.
if can't specify main cocoa thread then, there other way able create nswindow on background thread , receive events it? can't phone call nsapplication run because not in command of application's main loop. need pull input events window when upper level code requests so.
maybe need start runloop on secondary thread. in main thread, when spawn off secondary thread, phone call this:
[nsthread detachnewthreadselector:@selector(launchthread) totarget:[threadhandler class] withobject:nil];
in threadhandler class, have like:
+ (void)launchthread { nsrunloop *threadrunloop = [nsrunloop currentrunloop]; while (somethreadexitcondition && [threadrunloop runmode:nsdefaultrunloopmode beforedate:[nsdate datewithtimeintervalsincenow:1]]); }
this should start thread runloop processing events. i'm not sure without testing whether allow process events window created in secondary thread, might started on how run thread's runloop. set distributed objects situation pump events main event loop through nsconnection secondary thread (example). might @ to the lowest degree give avenue pursue.
osx cocoa
Comments
Post a Comment