我期望定期运行一个方法,但希望通过让它在单独的线程中运行来优化我的代码。到目前为止,我的代码看起来象下面这样:定时器方法运行哪个线程?
private System.Timers.Timer timerQuartSec = new System.Timers.Timer(250);
private Thread quarterSecThread;
timerQuartSec.Elapsed += new System.Timers.ElapsedEventHandler(someMethod);
quarterSecThread = new Thread(new ThreadStart(timerQuartSec.Start));
我的问题是,将这段代码只需启动定时器或将代码(上TimerElapsed)在新的线程上运行?
这可能会帮助你http://msdn.microsoft.com/en-us/magazine/cc164015.aspx –
@ K.B我明白它不会运行。这只是一个片段。前两行是实际方法之前的变量声明。 – GroomedGorilla
谢谢@HamletHakobyan。很棒的阅读,肯定帮助我理解了定时器类型之间的区别。幸运的是我使用的是正确的。 – GroomedGorilla