Re: Using NSThreads in command-line apps
Re: Using NSThreads in command-line apps
- Subject: Re: Using NSThreads in command-line apps
- From: Jens Alfke <email@hidden>
- Date: Thu, 15 May 2008 11:52:00 -0700
On 15 May '08, at 11:42 AM, ben syverson wrote:
Actually, I'm able to spawn new threads perfectly well. The problem
is that I can't (?) use performSelectorOnMainThread: because I'm not
an NSApplication, and so I don't get the default "main" thread that
loops for user input...
You don't need an NSApplication; all you need is an NSRunLoop on the
main thread.
To get one, you should structure your main thread's code like
... initialization ...
[[NSRunLoop currentRunLoop] run];
... teardown ...
The runloop call will cause the thread to block and repeatedly wait
for and then handle events, until there are no more runloop sources.
Runloop sources are things like NSTimers and the various -
performSelector... utilities declared in NSRunLoop and NSThread
("after delay", "on main thread", etc.)
If you know exactly when to quit and don't want to deal with removing
all runloop sources, you can just call exit(0) at the point where you
want to exit (after any necessary cleanup.)
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden