Main Site Documentation

Timer on specific time


#1

I need timer which trigger tick event every day at specific hour (my input is hour, minute, second for every day in week).
I tried with ExtendedTimer (http://msdn.microsoft.com/en-us/library/cc543952.aspx).
Does anybody know what the third parameters mean?
When will this be triggered:

ExtendedTimer t = new ExtendedTimer(call, null, new DateTime(now.y, now.m, now.d + 1,12, 0, 0),24*3600);

Tommorow at 12:00 or like the msdn say tomorow at 12:00 after a little more then 2013 years? (The System.DateTime value that represents the amount of time the timer will wait before the callback method invokes its methods, in milliseconds. )


#2

To answer my own question:

        void ProgramStarted()
        {
            Debug.Print("Program Started");

            DateTime date = new DateTime(2013, 6, 13, 12, 2, 0);
            Microsoft.SPOT.Hardware.Utility.SetLocalTime(date);


            Microsoft.SPOT.ExtendedTimer timer = new Microsoft.SPOT.ExtendedTimer(call, null, date.AddMinutes(2), new TimeSpan(0, 0, 10));
        }

        public void call(object o)
        {
            Debug.Print("Time: " + DateTime.Now.ToString());
        }

[quote]Program Started
The thread ‘’ (0x3) has exited with code 0 (0x0).
Time: 06/13/2013 12:04:00
Time: 06/13/2013 12:04:10
Time: 06/13/2013 12:04:20
Time: 06/13/2013 12:04:30
Time: 06/13/2013 12:04:40
Time: 06/13/2013 12:04:50
Time: 06/13/2013 12:05:00[/quote]
Exactly what I wanted.


#3

Hmm, maybe what you wanted, but not what you asked for…?


#4
ExtendedTimer t = new ExtendedTimer(call, null, new DateTime(now.y, now.m, now.d + 1,12, 0, 0),24*3600);

[quote]When will this be triggered:
Tommorow at 12:00 or like the msdn say tomorow at 12:00 after a little more then 2013 years?
[/quote]


#5

"The System.DateTime value that represents the amount of time"
The amount is crucial here for me. I understood that the timer will wait until the time is passed (all years, months, days, hours, minutes and seconds), not until the time is reached.


#6

If you want it every day then on each tic set it for the next tic. IE plus 1 day.


#7

Yep, a timer set for a specific time only fires once…and you should set a new time in the tic itself.