0
請幫助我瞭解如何在第一次不成功嘗試執行WPF DispatcherTimer之後,停止在dispatcherTimer.Tick
事件處理程序中執行MethodOne()
的嘗試。如何從Try - Catch中停止DispatcherTimer?
TimeSpan ts = new TimeSpan(0, 0, 5);
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = ts;
dispatcherTimer.Start();
...
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
try
{
MethodOne()
}
catch (Exception)
{
// Here I would like prevent code from trying to execute MethodOne()
}
}
我想設置一些鎖或停止計時器,而是試圖做到這一點我面臨的其它代碼的可視化問題,從一個try-catch建築內,不知道如何正確地解決它。