gpt4 book ai didi

c# - 调用自己来绕过不同的线程? C#

转载 作者:行者123 更新时间:2023-11-30 23:30:10 24 4
gpt4 key购买 nike

我已经四处寻找了大约 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);
}

关于c# - 调用自己来绕过不同的线程? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35054970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com