Re[2]: NSTimer not working in a multithreaded application
Re[2]: NSTimer not working in a multithreaded application
- Subject: Re[2]: NSTimer not working in a multithreaded application
- From: "Oleksiy Gorelov" <email@hidden>
- Date: Fri, 03 Sep 2010 09:59:14 +0300
Hello!
Probably you created your time in the worker thread. You should not use for this usual method invocations, NSNotificationCenter or performSelector: withObject:. Try to use - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg
waitUntilDone:(BOOL)wait; and create the timer in method invoked in the main thread
Oleksiy Gorelov
--- Исходное сообщение ---
От кого: "Wyatt Webb" <email@hidden>
Кому: "Abhijeet Singh" <email@hidden>
Дата: 3 сентября, 07:18:56
Тема: Re: NSTimer not working in a multithreaded application
>
> On Sep 2, 2010, at 7:37 PM, Abhijeet Singh wrote:
>
> > Hi,I am working on a multithreaded software that runs on a medical instrument. The software has 2 parts. GUI and worker threads (worker threads sends commands to instrument). The GUI is developed using ObjectiveC and Cocoa. Worker threads
are all in C and Carbon.It is a Cocoa application.I am working on GUI of the software.When the application starts it first creates worker threads ( that initializes the hardware/instrument). Once the threads are created one of the thread sends a message
back to main thread. My problem isi need to start a timer when the main thread receives a message from worker thread. I am starting a timer as follows:timer = [[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(turnOffLight:)
userInfo:nil repeats:NO] retain];But it does not work. I debugged it and found that the timer is created but "turnOffLight" is never executed.Then I created the timer just before worker threads creation and it worked. Can anybody help me in resol
> > ving this problem.Thanks & RegardsAbhijeetGet Yourself a cool, short @in.com Email ID now!Report spam
> > _
>
> How is the worker thread sending the message back to the main thread? Are you sure that the code is actually executing on the main thread? The NSTimer may not be scheduled on the main thread and that often means it won't get executed.
>
> If your message back to the main thread is a callback, try using performSelectorOnMainThread: to make sure the code is executed on the proper thread.
>
> Wyatt_______________________________________________
>
> 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
>
>
_______________________________________________
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