Application.DoEvents Method Processes all Windows messages currently in the message queue.
To understand how Application.DoEvents() method works, create a new winforms application and add a picturebox and assign a image and add a button to the form.
write the below code, in form1.cs file Form1_Load method and button1_Click method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
private void Form1_Load(object sender, EventArgs e) { pictureBox1.Visible = false; } private void button1_Click(object sender, EventArgs e) { pictureBox1.Visible = true; //Application.DoEvents(); System.Threading.Thread.Sleep(5000); pictureBox1.Visible = false; } |
Now run the above code.
When you click on button, you cannot see the picture box, though we are making picture box visible on button click.
Now uncomment the Applicaton.DoEvents line and run the code. You can see the picture box is visible on button click because calling Appliation.DoEvents method makes the current thread to be suspended all the waiting windows messages in the queue to be processed.