我想在另一个线程中更改计时器间隔:
class Context : ApplicationContext {
private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public Context() {
timer.Interval = 1;
timer.Tick += timer_Tick;
timer.Start();
Thread t = new Thread(ChangeTimerTest);
t.Start();
}
private void ChangeTimerTest() {
System.Diagnostics.Debug.WriteLine("thread run");
timer.Interval = 2;
}
private void timer_Tick(object sender,EventArgs args) {
System.Diagnostics.Debug.WriteLine(System.DateTime.Now.ToLongTimeString());
}
}
但是当我更改新线程中的间隔时,计时器会停止。没有错误,计时器只是停止。为什么会发生这种情况,我该如何解决?
谢谢