我试图从STA线程内部访问GUI元素(ToolStripStatusLabel)。我有各种各样的问题试图调用它,这就是现在我知道没有调用 ToolStripStatusLabel ,我的最新错误是: 错误1' System.Windows.Forms.ToolStripStatusLabel'不包含'调用
的定义我似乎无法在没有调用的情况下更新它,因为我收到错误: 的 System.NullReferenceException'发生
我有什么选择?我将如何进行此操作,从STA线程内部更改GUI线程上的statuslabel.text。
我已经使用了标准调用代码和控件扩展的所有庄园,但仍然存在相同的问题。
要求的代码:
private void buttonclick(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
var thread = new Thread(() =>
{
var ie = watinBrowser();
log("[!] Starting Application");
log("blahblah");
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private void log(string logIt)
{
statusUpdate(logIt);
}
private void statusUpdate(string text)
{
if (this.statusStrip1.InvokeRequired)
{
this.statusStrip1.Invoke(new MethodInvoker(() => this.toolStripStatusLabel1.Text = text));
}
else
{
this.toolStripStatusLabel1.Text = text;
}
}