Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,

I am using System.Threading.Timer to fire event after some time, which is working fine. i.e.

timervar = new System.Threading.Timer(methodname, null, 60000, 0);


I also want to fire event on specific time using the same. Is it possible? If yes, then how?

Regards!
Aman
Posted
Comments
JOAT-MON 23-Dec-10 2:45am    
Could you clarify what you are meaning: 'I also want to fire event on specific time using the same.'
Sergey Alexandrovich Kryukov 23-Dec-10 2:50am    
I thought this was clear: pick up some Calendar time, then make sure event is fired when this time comes.
Is that correct, Aman?
JOAT-MON 23-Dec-10 2:58am    
@SAKryukov - Lol...Obviously, based on his votes, I read a different/erroneous meaning from it.

One approach, Get the current time, after get the difference between current and scheduled time, wait till that duration and fire the event
 
Share this answer
 
Comments
Aman4.net 23-Dec-10 2:53am    
Thanx! I followed the same approach.
I used the approach recommended by Brij and achieved the result. the code is following:

TimeSpan myTimeSpan1 = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
TimeSpan myTimeSpan2 = new TimeSpan(20, 00, 00);
TimeSpan TsObj = new TimeSpan();
TsObj = myTimeSpan2.Subtract(myTimeSpan1);
Int32 milsec = Convert.ToInt32(TsObj.TotalMilliseconds);
My_Timer = new System.Threading.Timer(timer_click, null, milsec, 0);


Thanx for posting.
 
Share this answer
 
v2
use asp.net timer control for firing event on some time interval
 
Share this answer
 
I would fire the event inside the callback function. If it is going to be on a different timing, then give it its own callback method, else fire it from inside 'methodname'.
 
Share this answer
 

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