Winforms Application.DoEvents Method


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


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.

Zooming in Winforms Webbrowser Control in .NET
Filtering Datatable with Select Conditions and Sorting in C#.NET
Hiding a property from displaying in Datagridview in C#.NET
Logic to detect if Application is started from Citrix/Terminal Server/PC in C#
Modify XML file with tagname in c#.net
Read Machine IP Address in C#
Check if IIS is running using C#
Implementing IEnumerable in C#
Built in Delegates in .NET Framework
Changing Winform webbrowser control IE version in C#.NET
Set the dropdown width of any combobox based on the data
Difference between Const and ReadOnly
Example for Property Change Notification in C#.NET
Example Program using Delegates and Events in C#
AutoComplete in .NET Winforms TextBox
How to read data from XML String and insert in to table in SQL Server
WebBrowser.navigate Data Submission by Get or Post Methods
Datagridview Paging
Copy Datagridview cell value using ContextMenu
Inserting data in Datatable in C#
Cookie in .NET
Using Control's Child Index and Dock property for achieving desired layout in a form.
Accessing section group inside configuration of web.config
Create File in .NET C#
Change button shape in .net
Dispose vs Finalize in .net




Winforms Application.DoEvents Method C#.net Picture box not visible , winform UI thread busy not processing messages