RealTimeClock With Alarm for .Net Call backs?

Hello guys,
i was kind of wondering if it would possible to add to the RealTimeClock Class the ability to set alarms that will call back a .net function, kind of like the current Alarm but for software use…

this would be great to create events based on Date and Time… sort of a scheduler without the over head of creating a separate thread for that…

or is that something we can already do ?


can you use a Timer?

yes i can. but to me it would make a whole lot more sense to tap into the RealTimeClock processing, since it is already running in the background… instead of running my own timer that would essentially be doing the same thing.

does it make sense…?

so the new methods would be :

add event, remove events… passing a date and time of when the event would run… and my callback method / function.



Look at RealTimeClock.SetAlarm() method.

I think you can use this, and feed the Alarm pin into an Interrupt port.

Hi Mike,
the idea is to be able to add as many functions (Alarms) as i want to the RealTimeClock… without involving any hardware… this is pure software… that’s the idea anyway… kind of like i want at 01-01-12 12:00PM myMethod() would run, and while that is i can have another myMethod2 set to run at 01-13-12 2:00 PM and so on… so Alarm pin would be limited to calling the same interrupt if i’m reading it right…

thanks Mike.

Sounds like a fun thing to build. I have done it several times. Not a lot of code.

You could go to the MS .NET MF site and submit a request.

The question will be whether the functionality will be used by enough people to justify the necessary development and run-time resources to add it.

So you have done it using the timer i assume right? any sample code ?

maybe i will do it that way for now… until it gets implemented, i just hate the idea of wasting that extra processing power while another one is already running doing the exact same thing.


I think you are over estimating the resource saving of using the RTC. Most of the resources that are used go to maintaining the pending alarm queues, not keeping track of time.

I do not have sample code. The only code I have is written in C++ and it integrates with an application framework.

Yes timers do not use much to run. Using RTC alarm is just over complicating things and probably using more resources at the end.

I see thanks for clarifying things GUS…

I’ll mess with the timer and see if i can create a scheduler class that would allow me to set call backs…

thank you guys.


If you have any problems, let me know. There are some “interesting” aspects to queue management.

I know i will have questions…
thanks Mike.

I started to write a scheduler. A bit more complicated than I remembered. :smiley:

I hope to have it done within a day or so, and I will post in code section.

Cool Mike…

Thanks for sharing…


Hey Mike,
just thinking about this… now if i schedule an event that would mean i’ll have to create a new thread and a timer for each event correct?


I have finished the code, but it has only been tested under the emulator.

In my scheduler, there is one thread for managing the pending timer requests, and one or more worker threads for executing callbacks.

I thought a bit about where the execution of the expired event should occur. Since the scheduler is a shared resource, I thought it would not be good to execute an expiration event on the thread that is managing the pending timers. If the callback took a long time, then it could mess up the timers.

I choose to use a separate thread for executing the callbacks. In fact, when the scheduler is instantiated, there is an option to define multiple worker threads.

My knowledge of this topic is limited, but I also have been looking at using the RTC to schedule multiple alarms. The advantages I see of using the RTC over the extended timer is:

The RTC is run in hardware
The RTC will continue to run even if the main processor is hibernating
The RTC will wake-up the processor when an alarm event occurs[/ulist]

@ Mike thanks for the updates on the topic,
I will look at when i come back from Vacation and test it for you and report any changes… again thank you very much for your help.
@ jasdev: i agree with you, some of those were the reasons why i wanted it done at the RTC Level but as Gus pointed out it is harder to manage i guess. so for now i’ll do with this and most likely use the Current Alarm feature to always set the next event and monitor the interrupt… and when that event fires, create another alarm for the next event and continue on like that…

What do you think?


Remember that regardless of whether you use a software timer or the hardware RTC, you don’t have to schedule all the wake-ups, just the next wake-up.

Shouldn’t be that hard to manage, either way.

Hello Mike,
Would you mind posting your code, i’d like to start with the scheduler and wanted to see what you have done so far…

Happy New Year !!!