• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimer not working in a multithreaded application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer not working in a multithreaded application


  • Subject: Re: NSTimer not working in a multithreaded application
  • From: Nathan Day <email@hidden>
  • Date: Fri, 03 Sep 2010 12:48:21 +1000

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

On 03/09/2010, at 12:37, Abhijeet Singh <email@hidden> 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 res
 ol
> ving this problem.Thanks & RegardsAbhijeetGet Yourself a cool, short @in.com Email ID now!Report spam
> _______________________________________________
>
> 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

  • Follow-Ups:
    • Re: NSTimer not working in a multithreaded application
      • From: Dave DeLong <email@hidden>
References: 
 >NSTimer not working in a multithreaded application (From: "Abhijeet Singh" <email@hidden>)

  • Prev by Date: NSTimer not working in a multithreaded application
  • Next by Date: Re: NSTimer not working in a multithreaded application
  • Previous by thread: NSTimer not working in a multithreaded application
  • Next by thread: Re: NSTimer not working in a multithreaded application
  • Index(es):
    • Date
    • Thread