Re: Asynchronous timers (without a run loop)
Re: Asynchronous timers (without a run loop)
- Subject: Re: Asynchronous timers (without a run loop)
- From: "Påhl Melin" <email@hidden>
- Date: Fri, 5 Dec 2008 21:16:39 +0100
2008/12/5 Sherm Pendley <email@hidden>:
> 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?
Simply because I didn't know I was making things difficult for me.
>> 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.
That's why I asked in the first place. I didn't know how Cocoa works
in regards to timers. And so far, I've done most of my Mac programming
in BSD Unix where run loops are not used at all so it's not quite
super obvious how to implement multiple timer handling in Mac OS X. At
least I didn't think so.
/ Påhl
_______________________________________________
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