private void btnStartStop_Click(object sender, EventArgs e) { // do stuff depending on the text switch (btnStartStop.Text) { case "Start": { // create a new Messages object and pass it into the PowerNotifications // constructor MessageList = new Messages(); // create the powernotifications object pn = new PowerNotifications(ref MessageList); pn.Start(); // start a timer to monitor the messages queue if (timer1 == null) timer1 = new System.Windows.Forms.Timer(); timer1.Interval = 250; timer1.Tick += new EventHandler(ReadText); timer1.Enabled = true; btnStartStop.Text = "Stop"; } break; case "Stop": // stop the thread pn.Stop(); lstInfo.Items.Add("(" + System.DateTime.Now.ToString("hh:mm:ss") + ") stopping loop"); timer1.Enabled = false; btnStartStop.Text = "Start"; break; default: break; } }
private void btnStartStop_Click(object sender, EventArgs e) { // do stuff depending on the text switch (btnStartStop.Text) { case "Start": { // create a new Messages object and pass it into the PowerNotifications // constructor MessageList = new Messages(); // create the powernotifications object pn = new PowerNotifications(ref MessageList); pn.Start(); // start a timer to monitor the messages queue if (timer1 == null) { timer1 = new System.Windows.Forms.Timer(); } timer1.Interval = 250; timer1.Tick += new EventHandler(ReadText); timer1.Enabled = true; btnStartStop.Text = "Stop"; } break; case "Stop": // stop the thread pn.Stop(); lstInfo.Items.Add("(" + System.DateTime.Now.ToString("hh:mm:ss") + ") stopping loop"); timer1.Enabled = false; btnStartStop.Text = "Start"; break; default: break; } }