c# - blocking timer in windows service -
i using 'timer code' in windows service:
var autoevent = new autoresetevent(false); timer = new timer(dowork, autoevent, 0, timeinmilliseconds);
i wondering whether possible prevent invocation of dowork, if dowork has not finished yet? in other words, if timeinmilliseconds shorter time takes execute dowork?
if understand correctly can prevent automatic callback , change timer once when need.
timer = new timer(dowork, autoevent, 0, timeout.infinite);//prevent periodic timer void dowork(object state) { //do work , set timer again timer.change(timeinmilliseconds, timeout.infinite); }
don't forget add try/finally
block, if don't timer not called again in case of exception.
Comments
Post a Comment