C# Timer not resetting after displaying a messagebox, just displaying a new messagebox every second -


Me and my friends are making a podcastetter program for every 30 minutes, 60 minutes or 2 hours via RSS feed See and see if a new episode has been released or not. If so, new episodes should be added to the list of episodes in our program.

So, now we are trying to use the system. Timers To test our method to see new episodes of timer class to set the interval to implement our method, we want to print a message box every 10 seconds. But after 10 seconds, this program only keeps installing new message boxes. How can we reset the timer after 10 seconds and only display a new message box? Are we using the messagebox? If we do something other than displaying a message box, will it really be reset? We tried to print the information in the console but there was only one problem.

Ours is our code:

  using the system; Using System.Timers; Using System.Windows.Forms; Timer = system. By using the Times; Timer; Public Static Class TimerInitializer {public stable timer timer; // System stable start with public static zero (timer = new timer (10000); // Set the timer for 10 seconds // Type "_timer.Elapsed + =" and press the tab twice. // timer Apple + = New ElapsedEventHandler (Timer Apple); Timer Competent = true; // Enable} Public static zero timer alleased (Object Sender, ElapsedEventArgs e) {MessageBox.Show ("Hello"); }}  

You can disable the timer when the timer Deleted event fire, display message, then user MessageBox :

  public static zero timer has been removed (object sender, ElapsedEventArgs e ) From time to time {Timer.Stop (); // Stop the timer MessageBox.Show ("Hello"); Timer.start (); // restart it; You'll get another message in 10 seconds)  

Normally, the UI blocks the thread using the MessageBox.Show , and you will see that you do not click Can display a message on the UI during the display.

In addition to the UI thread, operates on its own thread. When the gap ends, it runs its code (in this case, displays a message), and then keeps shouting until you reach the next end again. The message you receive is too many message boxes None of them are blocking the UI or each other.

You can make the article a little old but information about different timers is still relevant.


Comments