我的C#應用程序正在使用一個計時器來確定是否在及時發生預期事件。這是我當前如何試圖做到這一點:C#中的計時器事件,增量和復位
// At some point in the application where the triggering event has just occured.
// Now, the expected event should happen within the next second.
timeout = false;
timer1.Interval = 1000; // Set timeout for 1 second.
timer1.Start();
timer1_Tick(object sender, EventArgs e)
{
timeout = true;
}
// At some point in the application where the expected event has occured.
timer1.Stop();
// At a later point in the application where the timeout is
// checked, before procedding.
if (timeout)
{
// Do something.
}
現在,我想知道是被稱爲Start()
或Stop()
成員方法時,不會導致定時器計數復位?我正在使用Microsoft Visual C#2008速成版。謝謝。
謝謝。我確實看過MSDN文章,但我一定錯過了這些信息。 – 2010-03-09 20:43:48