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建筑内,不知道如何正确地解决它。