While creating a sample Winforms application to demonstrate multithreading, I wrote the following code on the button click.
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Processing File. Please wait...";
Thread.Sleep(2500);
}
Ideally, the label text should be updated and then the thread should sleep, that is application becomes unresponsive. But what's really happening is, as soon as I click on the button, the application becomes unresponsive without updating the label value, and it gets updated only after the sleep interval has passed.
Am I missing something?
I understand why this is happening. But my question is, the thread should go to sleep only after updating the label text because that statement is above the sleep statement.
Is that something machine specific? Will it produce different results on different machines?