void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e) { if (this.InvokeRequired) { // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway. this.BeginInvoke(new EventHandler <SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e }); return; } Console.WriteLine(Encoding.ASCII.GetString(e.Data)); Timer timerIRSensorDelay = new Timer(); timerIRSensorDelay.Interval = trackBarSensorDelay.Value; timerIRSensorDelay.Enabled = true; timerIRSensorDelay.Tick += new EventHandler(timerIRSensorDelay_Tick); IRSensorCount += 1; lblIRSensorCount.Text = "IR Sensor Count: " + IRSensorCount; //Toggle every other coin: // toggleNextCoin = !toggleNextCoin; // if (toggleNextCoin) { //Timer timerToggleDelay = new Timer(); //timerToggleDelay.Interval = trackBarSensorDelay.Value + trackBarToggleDelay.Value; //timerToggleDelay.Enabled = true; //timerToggleDelay.Tick += new EventHandler(timerToggleDelay_Tick); // } }
void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e) { if (this.InvokeRequired) { // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway. this.BeginInvoke(new EventHandler<SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e }); return; } Console.WriteLine(Encoding.ASCII.GetString(e.Data)); Timer timerIRSensorDelay = new Timer(); timerIRSensorDelay.Interval = trackBarSensorDelay.Value; timerIRSensorDelay.Enabled = true; timerIRSensorDelay.Tick += new EventHandler(timerIRSensorDelay_Tick); IRSensorCount += 1; lblIRSensorCount.Text = "IR Sensor Count: " + IRSensorCount; //Toggle every other coin: // toggleNextCoin = !toggleNextCoin; // if (toggleNextCoin) { //Timer timerToggleDelay = new Timer(); //timerToggleDelay.Interval = trackBarSensorDelay.Value + trackBarToggleDelay.Value; //timerToggleDelay.Enabled = true; //timerToggleDelay.Tick += new EventHandler(timerToggleDelay_Tick); // } }