Re: Multithreading with DO and Notifications
Re: Multithreading with DO and Notifications
- Subject: Re: Multithreading with DO and Notifications
- From: Mike Davis <email@hidden>
- Date: Sat, 26 Apr 2003 19:05:34 +0100
Create a NSConnection between the worker thread and the main thread.
Make a call from the worker thread to the main thread via that
connection and have the main thread post the notification.
Be aware that the main thread will trigger at times you might not
expect. NSConnection allows you to control this so that the message is
received only in the main event loop. If you're not having to use
legacy code, then you almost certainly won't need to worry about this.
The NSThread documentation shows how to create such a basic mechanism.
On Saturday, April 26, 2003, at 04:09 pm,
email@hidden wrote:
Date: Sat, 26 Apr 2003 15:41:03 +1000
Subject: Multithreading with DO and Notifications
From: Greg Hulands <email@hidden>
To: email@hidden
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.
Regards,
Greg
_______________________________________________
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.