Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
我写了一个windows 应用程序,
当winform初始化以后,调用另外一个名空间的一个类的一个方法,
这个方法设置winform的一个Label的Text:
private Control control=new Control();
delegate void SetLabelCallback(string text);
#………………………………………………
void Status(string _msg) {
if (Form1.lb_status_obj.InvokeRequired == false)
{
Form1.lb_status_obj.Text = _msg;
}
else
{
SetLabelCallback sts = new SetLabelCallback(Status);
try
{
control.Invoke(sts, new object[] { _msg });
}
catch (Exception e)
{
cc.write_str(e.Message);//将错误写入文本
MessageBox.Show(e.Message);
System.Environment.Exit(0);
}
}
}
错误是“Invoke or BeginInvoke cannot be called on a control until the window handle has been created.”,这个错误是个啥子意思?怎样解决。
多线程访问winform真麻烦。