在我的应用程序中,我有一个用户控件,使用线程池执行异步操作。 线程池方法的样子如下:
private void AsyncFunction(object state)
{
... do the calculation
//refresh the grid data on the UI thread
this.BeginInvoke(new MethodInvoker(() =>
{
... update the ui
}));
}
我的问题是,如果用户关闭对话框,则用户控件将被处理,并且我会收到以下异常:
在窗口句柄创建之前,不能在控件上调用Invoke或BeginInvoke。
你知道有没有一种方法可以检测对话框是否已被处理?我不想在控件上设置一个对话框关闭时设置的属性。还有其他解决方法吗?
谢谢,
Radu