• 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: to implement a 1 sec repeating timer in a separate thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: to implement a 1 sec repeating timer in a separate thread


  • Subject: Re: to implement a 1 sec repeating timer in a separate thread
  • From: Dave Keck <email@hidden>
  • Date: Thu, 22 Oct 2009 01:31:52 -1000

Before I try to respond, I'd just like to say you've been mentioning
threads a lot, but you haven't said anything that convinces me that
more than one thread is necessary for what you're trying to do. Unless
you're doing some serious number crunching, video encoding, curing
cancer, etc. it's likely that you won't need any threads other than
the main thread. If, indeed, you simply want a timer to fire
every-so-often, then forget about threads - for this purpose, one
thread is all you'll need.

> But the doSomething is not getting called at all.
> May be because this thread is busy doing something else, so do I have to
> setup the timer in say main Thread.

You should be able to answer whether "this thread is busy doing
something else": Do you have a while() loop that never exits? How
about a sleep(666)? Why do you think the thread is "busy doing
something else" - is your app beachballing? Are you sure that the
timer is being created at all? (Put a breakpoint or an NSLog(@"timer
created"); before the line that creates the timer.)

Further, use the debugger! Pause your app after it's started up, and
see what it's doing. If it's in a CFRunLoop-derived function (ie,
mach_msg_trap()) then your run loop should be happily doing its thing.

> Earlier I was doing so, by setting up the timer by calling this setting up
> method as [self performSelectorOnMainThread:............], and it was
> working, but even after invalidating the timer, the timer was still
> referencing the object that contained NSTimer *timer.

That doesn't make sense - performSelectorOnMainThread:... doesn't
return a timer, so how could you invalidate it? Furthermore, I don't
understand "the timer was still referencing the object that contained
NSTimer *timer", nor do I see how that might relate to the timer
successfully invoking your method. :-/

So let's back up. From a user's perspective, what are you trying to
do? Also, it would probably do you some good to read these:

  http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Timers/Timers.html
  http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html
_______________________________________________

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

References: 
 >to implement a 1 sec repeating timer in a separate thread (From: Nick Rogers <email@hidden>)
 >Re: to implement a 1 sec repeating timer in a separate thread (From: Dave Keck <email@hidden>)
 >Re: to implement a 1 sec repeating timer in a separate thread (From: Nick Rogers <email@hidden>)

  • Prev by Date: Re: Search on Core data Table issue?
  • Next by Date: Re: Sending a Selector to another Class.
  • Previous by thread: Re: to implement a 1 sec repeating timer in a separate thread
  • Next by thread: NSTextField not getting mouseDown
  • Index(es):
    • Date
    • Thread