views:

89

answers:

1

Hi i want implement a windows services scheduled task. I already created windows service. In a service i have implemented a timer.The timer is initialized at class interval. The timers interval is set in the start method of service and also it is enabled in the start method of the service. After timers elapsed event is fire i have done some actions.

My problem is that, i am in a dilemma. Lets say the action i have done in Elapsed event, lets say take one hour and the timers interval is set to half an hour. so there are chances that even if the previous call to elapsed event has not ended new call to elapsed event will occur.

my question will there be any conflict or is it ok or shall i use threads. please give some advice

A: 

You can stop the timer at the begining of your long running method, then start it again at the end:

Timer.Change(Timeout.Infinite, Timeout.Infinite)
// do long task ...
Timer.Change(dueTime,period)
TheSean