Friday, February 24, 2017

C# - Hide "Not Responding" message on Windows Form application

Sometimes, in a Windows Form application, we have a situation that make the application "Not Responding". This is not good from user's perspective. If any improvement cannot make any changes, you can choose a solution to hide the message from the application. The following application show you a case of "Not Responding" and a version that can hide the message.

This function will make the application "Not Responding".

     private void button1_Click(object sender, EventArgs e)  
     {  
       for (int i = 0;i < 100000000; i++)  
       {  
         label1.Text = "i = " + i.ToString();  
       }  
     }  


However, adding the following code, you can see no "Not Responding" on your application.
     [DllImport("user32.dll")]  
     public static extern void DisableProcessWindowsGhosting();  
     private void Form1_Load(object sender, EventArgs e)  
     {  
       DisableProcessWindowsGhosting();  
     }  


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.