Re: Asynchronous timers (without a run loop)
Re: Asynchronous timers (without a run loop)
- Subject: Re: Asynchronous timers (without a run loop)
- From: Sherm Pendley <email@hidden>
- Date: Fri, 5 Dec 2008 11:30:36 -0500
On Dec 5, 2008, at 7:52 AM, Påhl Melin wrote:
...to have the TimerFunction() function be called twice per second
after 5 seconds (time in millisecond). Nothing else – you don't need
to idle your thread at all. Dotnet handles everything by itself.
Setting up multiple timers is just repeating the line of code above.
(gcnew is just new on the garbage collect heap and the carret '^' is
just a pointer/handle to the garbage collect heap if you don't know
Microsoft C++/CLI)
Since it's so easy in Dotnet and Cocoa (plus the other API:s in Mac OS
X) is even more mature, I just assumed it would be just as easy in Mac
OS X. But it seems I was wrong.
No, you were right. Doing such a thing is quite easy in Cocoa. It's
just like in .NET, a single call to a NSTimer class method, that
accepts arguments giving the interval, callback object, and the
message to send to that object when the timer fires.
Of course, if you happen to already
use an event-driven design using run loops in Cocoa/Core Foundation
it's very easy here as well. But since I'm not...
So why aren't you? If you choose to make things difficult for
yourself, they will be. Why do you find that surprising?
Thanks everyone for giving me advice on setting up a separate thread
with a run loop (of any kind) to handle timers. It seem like the best
solution to make my own Timer API with a separate thread to simulate
the Dotnet Timer API. I just wish didn't have to.
You're trying to act as if Cocoa is "supposed" to work like .NET, but
no one is "making" you do that. You're asking for trouble, and getting
what you asked for.
You'd have far, far less trouble programming for the Mac if you'd
simply learn how Cocoa works, instead of trying to reinvent .NET in
Objective-C. When in Rome, do as the Romans do.
sherm--
_______________________________________________
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