Re: NSRunLoop performSelector question
Re: NSRunLoop performSelector question
- Subject: Re: NSRunLoop performSelector question
- From: Dustin Voss <email@hidden>
- Date: Thu, 11 May 2006 18:27:19 -0700
On 11 May 2006, at 9:22 AM, Craig Hopson wrote:
In my app I use several threads to handle various processing
tasks. The processing starts when a button is clicked and proceeds
until the data is used up. Each of the various threads may finish
their part at a different time, so they signal back to the main
thread via a callback. In the callback I set a flag for each
thread as it calls. When all of the threads have reported in, I call
[ _mainRunLoop performSelector:@selector(myCleanup)
target:self
argument:nil
order:10
modes:
[ NSArray arrayWithObject:NSDefaultRunLoopMode ]];
This works well but for one thing... If I keep hands off the
application - no key events, no mouse clicks, etc. - the selector
is never called (well, I been patient enough to wait 30 seconds).
As soon as I click the mouse, hit a key, etc. the selector is
called. I assume the run loop is waiting for some input to run.
So, how do I trigger this?
Shawn Erickson gave an alternate solution, but I think I know why
this might not be working.
When a worker thread makes its "I've finished" call, that method is
still executed in the context of the worker thread. As the
documentation says, "You should never try to call the methods of an
NSRunLoop object running in a different thread, as doing so might
cause unexpected results."
(file:///Developer/ADC Reference Library/documentation/Cocoa/
Conceptual/InputControl/index.html#//apple_ref/doc/uid/10000062i)
In this case, your worker thread is trying to call a method on the
main thread's run loop, but that run loop is operating out of the
main thread, not the worker thread.
Your code should work fine if you make the "I've finished" or
"myCleanup" calls with -performSelector:onMainThread:...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden