C# 在其他线程关闭窗体,为何不能null
我的意图是将一个窗体作为一个控件,在主窗体显示,在另一Timer线程中关闭,关闭之后为何窗体对象还是不为null
代码如下:
//查询 if (w == null) { w = new wait(); w.LabelText = "正在查询,请稍候"; w.TopLevel = false; //将子窗体作为控件显示 w.TopMost = true; w.BringToFront(); w.Location = new System.Drawing.Point(dataGridView.Width / 2 - dataGridView.Location.X - w.Width / 2, dataGridView.Height / 2 - dataGridView.Location.Y);//将子窗体显示在主窗体中间位置, dataGridView.Controls.Add(w);//将子窗体的父容器设置为datagridview w.Show(); }
/// <summary> /// 关闭进度窗 /// </summary> void closewait() { if (w != null) { w.Close(); w.Dispose(); this.Focus(); } }
if (w== null || w.IsDisposed){}