Click here to Skip to main content
15,896,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used the the system.threading.timer to excute the particular task after 1 hour .i have used the following code for the timer
            TimeSpan tsDueTime = new TimeSpan(1, 0, 0);
            TimeSpan tsPeriod = new TimeSpan(1, 0, 0);
TimerCallbacktime rDelegate = new TimerCallback(databaseTrensfer);
timer1[timer] = new System.Threading.Timer(timerDelegate, obj, dueTime,interval);


it excute the timer after 1 hour correctly .but when i have started the application at 1:30 then it will excute the timer after 1 hour at 2:30--3:30--4:30.but i want to excute the time according to the system clock like , when i have started the timer at 1:30 then next timer excute at 2:00 --3:00--4:00 .how to set the threading.timer to excute according to the system clock changes?
Posted
Updated 29-Jan-12 22:38pm
Comments
Sergey Alexandrovich Kryukov 30-Jan-12 4:41am    
Why? What's the ultimate purpose of it? Using timers is generally questionable.
--SA

1 solution

You can do it in combination with polling of the current time using System.DateTime.Now, http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

Suppose you get a current time and determine that you need next event in a number of milliseconds which corresponds to 23:13:329 (minutes:seconds:milliseconds). Set a timer for this period to come to the next event at the boundary rounded by hours, and then change the timer to tick hourly. Something like that.

—SA
 
Share this answer
 
Comments
vrushali katkade 30-Jan-12 4:59am    
thanks for the reply ,how to specify the start time to the threading.timer like window schedular? please provide the example

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900