2012-02-12 88 views

回答

2
myTimer.Tick += new EventHandler(TimerEventProcessor); 

// Sets the timer interval to 5 seconds. 

myTimer.Interval = 5000; 

myTimer.Start(); 

這將導致TimeEventProcessor在5秒內執行而不會阻塞當前線程。

5

創建

Timer _timer = new Timer(); 

定時器初始化

_timer.Interval = 5000; // Time in milliseconds. 
_timer.Tick += Timer_Tick; 
_timer.Start(); 

計時器的計時器滴答事件處理

void Timer_Tick(object sender, EventArgs e) 
{ 
    // Do the timed work here 
} 

您可以

_timer.Stop(); 
0123停止計時器

UPDATE

可以將System.Windows.Forms.Timer -component到Form添加(到其元件托盤是精確的)。這具有可以從屬性窗口設置其屬性和Tick-event的優點。

還請查看其他計時器的文檔:System.Threading.Timer,System.Timers.Timer,System.Web.UI.TimerSystem.Windows.Threading.DispatcherTimer。阿布舍克蘇爾寫了一個不錯的比較here

相關問題