Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to display a message box in every 1 minute in c# windows application
Posted

C#
private void button1_Click(object sender, EventArgs e)
      {
          while (true)
          {
              System.Threading.Thread.Sleep(60 * 1000);
              MessageBox.Show("Hello!");
          }
      }


OR

C#
private void button1_Click(object sender, EventArgs e)
     {
         while (true)
         {
             System.Threading.Thread showSeperate = new System.Threading.Thread(new System.Threading.ThreadStart(Show_Message));
             System.Threading.Thread.Sleep(60 * 1000);
             showSeperate.Start();
         }
     }
     void Show_Message()
     {
         MessageBox.Show("Hello!");
     }
 
Share this answer
 
Comments
sureshbalachander 16-Sep-10 1:51am    
Hi,

Adding comments to your code,
1) Using While(true) in button_click event will hang the window form, because the while loop will never come to an end and hence the click event will not get completed.
2) The second method is good, but the while loop should be in "Show_Message" method and also, thread should run in background. (IsBackground = true;)

Correct me, if i am wrong.

Regards,
Suresh
santhosh1985april 16-Sep-10 5:50am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
Hi,

You can also try using Threading. Make the thread to wait for 1 minute using "Thread.Sleep" method.

Regards,
Suresh
 
Share this answer
 
Comments
santhosh1985april 16-Sep-10 5:50am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
Use Timer control, and display Message Box in its Tick event.
Search google to get the functionality of a Timer Control. Its very simple.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900