创建的子窗体不能ShowDialog(),模态窗体无法调用委托时,会卡在invoke
public void SetCaption(string newCaption)
{
if (this.lblCaption.InvokeRequired)//如果调用控件的线程和创建创建控件的线程不是同一个则为True
{
while (!this.lblCaption.IsHandleCreated)
{
//解决窗体关闭时出现“访问已释放句柄“的异常
if (this.lblCaption.Disposing || this.lblCaption.IsDisposed)
return;
}
SetCaptionCallback d = new SetCaptionCallback(SetCaption);
lblCaption.Invoke(d, new object[] { newCaption });
}
else
{
this.Caption = newCaption;
this.lblCaption.Text = newCaption;
progressShow.PerformStep();
this.Refresh();
}
}
在函数体里启动了一个线程,线程后面不能还有其他占用资源的代码,否则刚启动的线程会卡住