/ Published in: C#
Expand |
Embed | Plain Text
using System; using System.Windows.Forms; namespace WindowsFormsTimer { public class Class1 { static int alarmCounter = 1; static bool exitFlag = false; // Timer raised method private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { theTimer.Stop(); // Displays a message box asking whether to continue running the timer if (MessageBox.Show("Continue running?", "Count is " + alarmCounter, MessageBoxButtons.YesNo) == DialogResult.Yes) { // Restarts the timer and increments the counter alarmCounter += 1; theTimer.Enabled = true; } else { // Stops the timer exitFlag = true; } } public static int Main() { //Adds the event and the event handler for the method that will //process the timer event to the timer // Sets the timer interval to 5 seconds theTimer.Interval = 2000; theTimer.Start(); // Runs the timer, and raises the event while (exitFlag == false) { // Processes all the events in the queue Application.DoEvents(); } return 0; } } }
You need to login to post a comment.
