WPF UserControl销毁前处理
程序员文章站
2022-06-08 23:04:19
...
若需要在销毁UserControl前执行操作,不能指望使用Unloaded方法,你需要在UserControl的构造函数中增加类似如下代码:
public UCCaptureQuery()
{
InitializeComponent();
Dispatcher.ShutdownStarted += (object sender, EventArgs e)=>
{
_stopThread = true;
if (null != _threadReadStatus)
{
_threadReadStatus.Join();
_threadReadStatus = null;
}
};
}
转自http://geekswithblogs.net/cskardon/archive/2008/06/23/dispose-of-a-wpf-usercontrol-ish.aspx
下一篇: 简单自定义标签步骤
推荐阅读