调用自己来绕过不同的线程? C#
Invoke self to bypass different threads? C#
我已经四处寻找了大约 3 个小时,但无法使此调用起作用。我需要调用,因为调用它的是在不同的线程中并且说它不稳定。
我是这么叫的(我是这样叫的textBox1_TextChanged(null, null);
):
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(this.InvokeRequired)
{
this.Invoke(this?WHAT GOES HERE, null); // I know it should be a delegate or something but I can't change this to that
}
else
{
string temp = "";
temp += TextToAdd;
textBox1.Text = "s";
}
}
您可以使用 BeginInvoke 从其他线程更新 UI。
if (this.InvokeRequired)
{
var action = new Action(() => textBox1.Text = "s");
this.BeginInvoke(action);
}
我已经四处寻找了大约 3 个小时,但无法使此调用起作用。我需要调用,因为调用它的是在不同的线程中并且说它不稳定。
我是这么叫的(我是这样叫的textBox1_TextChanged(null, null);
):
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(this.InvokeRequired)
{
this.Invoke(this?WHAT GOES HERE, null); // I know it should be a delegate or something but I can't change this to that
}
else
{
string temp = "";
temp += TextToAdd;
textBox1.Text = "s";
}
}
您可以使用 BeginInvoke 从其他线程更新 UI。
if (this.InvokeRequired)
{
var action = new Action(() => textBox1.Text = "s");
this.BeginInvoke(action);
}