Problem with detached thread
Problem with detached thread
- Subject: Problem with detached thread
- From: Laurent Daudelin <email@hidden>
- Date: Thu, 04 Jul 2002 03:02:22 -0400
Hi!
I have a little problem and I'm sure there must be some solution to it.
I'm working on an app that has to perform a lengthy file system operation.
During which I display a sheet with a stop button. If I just run the app
like this, the spinning wheel of death appears and no matter how many times
I try, the stop button doesn't respond to my mouse clicks, or to the
associated keyboard shortcut.
So, I thought I would detach the lengthy operation in a new thread. The
problem is that based on some stuff processed by this operation, I need to
display a window.
I then split my lengthy method in 2 parts because the method would complete
immediately after detaching the thread, and since the lenghty stuff is not
done, I can't display the window. So, I ended up with 2 methods: the initial
method is executed in the detached thread, and the remaining part, where the
window is filled and then displayed should be executing in a second method,
in the main thread, because it doesn't take very long and because I don't
want that window to be somehow trapped in my detached thread. We've always
heard that AppKit wasn't thread-safe, even though I've read documents from
Apple that put some nuance on this.
So, anyway, I'm looking for a way to call the second method to complete the
operation by displaying a window, but I've been unable to make it executes
in the main thread. I did write a method to handle the
NSThreadWillExitNotification, but since that notification is sent from the
detached thread just before it exits, I'm getting nowhere with that. I've
tried in the notification method to send a perform:withObject:afterDelay:
but it seems like my object never receives that message, maybe because when
sending it, the thread is about to exit, I'm not sure.
I'm sure there must be some way to have the interface responsive without
messing up the application too badly.
So, what are my choices?
Thanks in advance!
-Laurent.
--
============================================================================
Laurent Daudelin <
http://members.cox.net/nemesys>
Logiciels Nemesys Software
mailto:email@hidden
fat-finger vt.: 1. To introduce a typo while editing in such a way that the
resulting manglification of a configuration file does something useless,
damaging, or wildly unexpected. "NSI fat-fingered their DNS zone file and
took half the net down again." 2. More generally, any typo that produces
dramatically bad results.
_______________________________________________
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.