Reputation: 2293
I have a WinForms program that has a button
, a statusStrip
, and a toolStripStatusLabel
in that statusStrip
. If I click the button and this runs:
private void button1_Click(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "Test";
System.Threading.Thread.Sleep(5000);
}
Then the toolStripStatusLabel
's text doesn't update until after the thread is done sleeping. How do I get it to update immediately, then sleep the thread?
Upvotes: 5
Views: 11541
Reputation: 1
Do NOT add the text change code here, cause it will be refreshed only after a click on it (as you can see on the picture - statusStrip1_ItemClicked) so, any statusStrip1.Update(); this.Update(); etc can't help you.
if
where the target condition started
like in this pictureUpvotes: 0
Reputation: 1561
My status label change wasn't showing at runtime when the status strip had Spring set to true. I set Spring to false and it began showing.
Upvotes: 0
Reputation: 1
Last solution with Application.DoEvents()
is the best. Application.DoEvents()
must be appended to each StatusStrip change:
private void SetParseStatus(object sender, ParseStatusChangedEventArgs e)
{
toolStripProgressBar1.Value = e.Percent;
Application.DoEvents();
}
Upvotes: -1
Reputation: 2293
As P. Kouvarakis said, the solution was this:
toolStripStatusLabel1.Text = "Test";
statusStrip1.Update();
Upvotes: 8
Reputation: 549
toolStripStatusLabel1.Text = "Test";
Application.DoEvents();
Upvotes: -1