WebForm:从另一个线程更新文本框

WebForm: Update textbox from another thread

在 WebForm 中,如何从另一个线程更新文本框

lock (tbConsole)
{
    tbConsole.Text += "\r\n server:" + text; 
}

您需要使用控件的Invoke方法来运行UI线程上的代码:

tbConsole.Invoke(new Action(() => tbConsole.Text += "\r\n server:" + text));

你通常不会。

代码隐藏在服务器上执行,然后生成的页面被发送到client/browser。到那时,您的 C# 代码隐藏的生命周期就结束了。