Re: Terminating from Separate Thread
Re: Terminating from Separate Thread
- Subject: Re: Terminating from Separate Thread
- From: James Bucanek <email@hidden>
- Date: Tue, 11 Jul 2006 17:00:01 -0700
Eric Blanpied wrote on Tuesday, July 11, 2006:
>My app has a child object that handles a periodic process on a
>separate thread. From time to time that process encounters an error
>which requires notifying the user and quitting the app. So far I've
>done this with an NSAlert from that thread, and then [NSApp
>terminate: self], which seems effective.
Someone can correct me, but my understanding is that you should never every do this. All UI APIs should be called exclusively from the main thread. Non-main threads should never try to do any direct user interaction or UI event handling.
>The trouble is that there are some things that would be good to tidy
>up in the main thread before even showing that alert. How can I have
>this child object, on a separate thread, tell the main app to do some
>stuff, show the dialog (with error data from the child object), & quit?
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
Create a method to handle your shutdown/cleanup situation. When you encounter the condition on your alternate thread, have the thread queue up a message to be sent on the next event loop of the main thread:
[myApp performSelectorOnMainThread:@selector(goByeBye) withObject:nil waitUntilDone:NO];
--
James Bucanek
_______________________________________________
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