C#-UI线程中的计时器

时间:2018-09-20 06:07:23

标签: c# synchronization

有一个计时器,每秒执行一次。

此计时器执行一次需要0.5秒。

如果在计时器功能运行时单击另一个按钮,我想知道计时器是否立即停止运行,或者在计时器完成后是否执行其他操作。

另外,在相反的情况下,当单击按钮并运行该功能时,也想知道计时器的功能是否应在1秒后运行。

System.Windows.Form.Timer TestTimer = new System.Windows.Forms.Timer(this.components);
TestTimer.Interval = 1000;
TestTimer.Tick += new System.EventHandler(this.TestTimerFunc);

private void TestTimerFunc(object sender, EventArgs e)
{
    // 0.5 sec
}

System.Windows.Forms.Button TestButton = new System.Windows.Forms.Button();
TestButton.Click += new System.EventHandler(this.TestButtonFunc);

private void TestButtonFunc(object sender, EventArgs e)
{
    // 5 sec
}

0 个答案:

没有答案