Re: Multithreading with DO and Notifications
Re: Multithreading with DO and Notifications
- Subject: Re: Multithreading with DO and Notifications
- From: Drew McCormack <email@hidden>
- Date: Sat, 26 Apr 2003 10:47:01 +0200
On Saturday, April 26, 2003, at 07:41 AM, Greg Hulands wrote:
In my application I detach a worker thread to import a heap of images.
It communicates with a model object via DO so it can update its status
of the percentage completed of the import. In the update progress
method it looks like this
- (void)inputCaptureCompletionChanged:(float)amount
{
_inputCaptureCompletion = amount;
[self didChange];
if ((int)amount == 1)
[[NSNotificationCenter defaultCenter]
postNotificationName:DLSOrderCompletedInputCaptureNotification
object:self];
}
The problem occurs when the notification gets posted that because
NSNotificationCenter is syncro it then dispatches the notification
before the thread the called it has exited. I have searched mamasam but
could not find a definitive solution. Does anyone have any suggestions
on how to solve this as I am architecturally going out of my mind. I
have tried making a timer fire to post the notification, but the same
thing still happens.
Any help is greatly appreciated.
Hi Greg,
I'm not quite sure what your problem is, but if I understand correctly,
you want the notification to be received in the main thread, not the
worker. Is that right?
If that is it, why not put the postNotif... call alone in a private
method, and use the NSObject method
- performSelectorOnMainThread:withObject:waitUntilDone:
to call the private method in the main thread.
That is, something like this:
- (void)inputCaptureCompletionChanged:(float)amount
{
_inputCaptureCompletion = amount;
[self didChange];
if ((int)amount == 1)
[self performSelectorOnMainThread:@selector(_notifyOfCompletion)
withObject:nil waitUntilDone:NO]; // Maybe you need YES instead of NO
}
-(void)_notifyOfCompletion {
[[NSNotificationCenter defaultCenter]
postNotificationName:DLSOrderCompletedInputCaptureNotification
object:self];
}
Hope this helps,
Drew
----------------------------------
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Stock Market strategy design platform for Mac OS X.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.