Re: NSTimer not working in a multithreaded application
Re: NSTimer not working in a multithreaded application
- Subject: Re: NSTimer not working in a multithreaded application
- From: Dave DeLong <email@hidden>
- Date: Thu, 02 Sep 2010 20:51:15 -0600
Just a minor correction:
All threads have a run loop created automatically, but only the main thread's run loop is running by default (if it's a GUI application). If you're on a secondary thread, you have to spin the run loop manually using one of its "run..." methods.
But (in essence) you're correct that the run loop of the secondary thread is not running, which means it's not processing timer events.
Dave
On Sep 2, 2010, at 8:48 PM, Nathan Day wrote:
> NSTimers rely on there being an NSRunLoop for the current thread, so if you are creating a timer in a thread without a run loop it will not work, because the is no run loop to add the timer to. From the sounds of it you also want the timer to be executed in the main thread, in which case you will have to use one of the perform in main thread methods so the creation of you timer can happen in the main thread. You may alternatively be able to create a time and manually add it to the main runloop if the methods for that are thread safe, but I don't think they are.
>
> Sent from my iPad
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