之间有什么区别
System.Threading.Timer
System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(PerformAction), null, 0, 15000);
和
在新线程内使用System.Timers.Timer?
Thread thread = new Thread(new ThreadStart(PerformActionWithTimer));
thread.Start();
void PerformActionWithTimer()
{
//Timer inside this
}
最佳答案
没有System.Windows.Timer
这样的东西。想必您是指System.Windows.Forms.Timer
。永远不要尝试在多线程方案中使用该类。它在UI线程上引发Tick
事件,仅此而已。如果您希望计时器引发辅助线程上的事件,请使用System.Timers.Timer
。完全没有理由直接使用System.Threading.Timer
。