Re: Stopwatch
Re: Stopwatch
- Subject: Re: Stopwatch
- From: Joshua Orr <email@hidden>
- Date: Sun, 12 Jun 2005 13:28:55 -0600
> On Sun, 12 Jun 2005 11:14:42 -0700, mmalcolm crawford wrote:
>
>> Use an NSTimer instead:
>>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/Timers/index.html>
>
> Ok.
> But that's not the point. When it comes to fire the timer, the whole
> interface freezes.
> That's why I used a different thread.
No, what he ment was you use a repeating timer to update your interface.
When the user presses a start button, then you grab the current time and
save that somewhere, and start a repeating timer.
The timer will repeadtly invoke some update method so you can update the
display so the user knows how much time has passed (as it's counting).
When the user presses stop then you kill the timer (invalidate it).
If you really want to use a different thread, then you can check a variable
in your infinite for loop. As long as only one thread changes is and the
other only reads the variable, then you don't have to worry about locking
the variable.
So the main thread sets the variable to 'NO' and your other thread sees that
and simply returns (breaks from the for loop). When the method that you
started the thread with returns, the thread goes away.
You can't use a stack varaible for this, needs to be a common variable in a
object, or a static variable.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden