立即更新 toolStripStatusLabel

der*_*can 4 c# multithreading statusstrip toolstripstatuslabel

我有一个WinForms程序,有一个button,一个statusStrip,和toolStripStatusLabelstatusStrip。如果我单击按钮并运行:

private void button1_Click(object sender, EventArgs e)
{
    toolStripStatusLabel1.Text = "Test";

    System.Threading.Thread.Sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)

然后,toolStripStatusLabel直到线程完成睡眠后, 的文本才会更新。如何让它立即更新,然后让线程休眠?

der*_*can 7

正如P. Kouvarakis所说,解决方案是这样的:

toolStripStatusLabel1.Text = "Test";
statusStrip1.Update();
Run Code Online (Sandbox Code Playgroud)