【发布时间】:2021-04-03 15:42:44
【问题描述】:
我正在尝试取消订阅另一个事件中的一个事件,但我不知道我应该如何处理这个问题,或者是否有一个简单的模式。我已经查看了 Microsoft 的官方文档,但没有找到任何解决问题的方法。
private void bTrainingD_Click(object sender, RoutedEventArgs e)
{
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler(dispatcherTimer_Tick);
timer.Start();
}
...
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (true)
{
//some code here
}
else
{
// unsubscribe or stop the Tick-Event here
}
}
感谢您的帮助。 :-)
【问题讨论】:
标签: c# wpf events event-handling unsubscribe