1

Can I use this code snippet as a complete replacement to traditional System.Timers that will run for as long as my application/service is running?

System.Threading timer:

var timeToWait = TimeSpan.FromSeconds(20);
var interval = TimeSpan.FromMinutes(5);
var t = new Timer(s => OnTimedEvent(), null, timeToWait, interval);

System.Timers timer:

timer = new Timer(interval);
timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
timer.Start();

The System.Threading version works for me so far so good, but are there any long term implications with the above code?

4

1 回答 1

1

关于线程安全问题有一点不同。

您将在此处获得详细信息System.Timers.Timer 与 System.Threading.Timer

于 2013-07-10T05:56:04.507 回答