在backgroundWorker run之前show出了一个窗体_frm.
_frmpw = new FrmPleaseWait();
_frmpw.SetMsg("正在请求");
_frmpw.Show();
bw.RunWorkerAsync();
在backgroundWorker RunWorkerCompleted事件中准备去关闭这个窗口
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (_frmpw != null && !_frmpw.IsDisposed)
_frmpw.Close();
。
如果DoWork事件中的任务完成的非常快,_frmpw还未创建完成时就去访问_frmpw.IsDisposed属性就会出现Value Dispose() cannot be called while doing CreateHandle().
解决方法,只能在DoWork事件中加SLEEP了。
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(300);//防止Value Dispose() cannot be called while doing CreateHandle()
-----------