Re: Threads, Distributed Objects, and NSUndoManager
Re: Threads, Distributed Objects, and NSUndoManager
- Subject: Re: Threads, Distributed Objects, and NSUndoManager
- From: m <email@hidden>
- Date: Sat, 16 Oct 2004 15:50:47 -0700
On Oct 16, 2004, at 12:40 PM, John C. Daub wrote:
Now I have refactored my application a bit so that while the work is
going
on I display a progress sheet with progress bar and Stop button. To do
this,
I had to put my work into a thread. But from what I was reading about
threads, since I'm going to need to have the thread collect my data
then
pass the data back to the main thread, I need to use something like
distributed objects to pass that data back.
[snip]
My guess is because the data object I'm
actually given isn't the real data object but instead an NSProxy
version of
the object...
I think your guess is right on.
You don't need to use DO, though it is sometimes more convenient. You
just need to ensure that your threads aren't accessing your data object
at "at the same time".
Here's a strategy: have your main thread allocate the data object and
pass it to your worker thread (without retaining a reference to it),
then you can just have the worker thread hand it back when it's done
(perhaps by calling
performSelectorOnMainThread:withObject:waitUntilDone: on some suitable
selctor).
something like this (typed in mail, not tested, obviously)
- (void) kickOffLongOperation
{
[NSThread detachNewThreadSelector:@(longOperation:) toTarget:self
withObject:[[MyDataThing alloc]init]];
}
- (void) hereIsTheResult:(MyDataThing*)dataThing
{
// pop the data thing on the undo stack
....
}
- (void) longOperation:(MyDataThing*) dataObject
{
...
while (stillComputing)
{
[dataObject add
Data:moreData];
}
// all done, transfer object to main thread
[objectInMainThread
performSelectorOnMainThread:@selector(hereIsTheResult:)withObject:
dataObject waitUntilDone:NO];
...
}
_murat
_______________________________________________
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