我有一個winform函數,每x次執行一次(例如每60分鐘)。
然後它做了一些事情,然後我希望它等待幾秒鐘(使用計時器),然後執行一些東西part2。無法觸發事件(定時器)
private void goToFtp(int time)
{
double interval = time* 60 * 1000;
System.Timers.Timer checkForTime = new System.Timers.Timer(interval);
checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
checkForTime.Enabled = true;
}
System.Windows.Forms.Timer timerDelayWatcher = new System.Windows.Forms.Timer();
private void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
{
.......Do some stuff part1
timerDelayWatcher.Tick += new EventHandler(timerDelayWatcher_Tick); // Everytime timer ticks, timer_Tick will be called
timerDelayWatcher.Interval = (1000) * (5);
timerDelayWatcher.Enabled = true;
timerDelayWatcher.Start();
}
private void timerDelayWatcher_Tick(object sender, EventArgs e)
{
timerDelayWatcher.Stop();
.......Do some stuff part2
}
問題是,timerDelayWatcher_Tick沒有被解僱......任何ideias爲什麼?
剛剛測試過您的代碼。它適用於我....你確定它執行「做一些東西第1部分」的代碼? – User999999