在我的应用程序中,我有一个用户控件,使用线程池执行异步操作.线程池方法如下所示:
private void AsyncFunction(object state)
{
... do the calculation
//refresh the grid data on the UI thread
this.BeginInvoke(new MethodInvoker(() =>
{
... update the ui
}));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果用户关闭对话框...用户控件被释放,我得到异常:
在创建窗口句柄之前,无法在控件上调用Invoke或BeginInvoke.
你知道一种检测对话框是否处理的方法吗?我不想在关闭时设置对话框设置的控件属性.还有另一种解决方法吗?
谢谢,
拉杜
max*_*max 21
你可以使用Control.IsDisposed
财产.
try
{
if(!this.IsDisposed)
{
this.BeginInvoke(new MethodInvoker(() =>
{
// update my control
}
));
}
}
catch ( InvalidOperationException )
{
// Do something meaningful if you need to.
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7467 次 |
最近记录: |