private void Form1_FormClosing(object sender, FormClosingEventArgs e) { var tmp = mmTimer; if (tmp != null) { mmTimer = null; tmp.Dispose(); } }
public Form1() { InitializeComponent(); serialPort1.WriteBufferSize = 10; var names = SerialPort.GetPortNames(); if (names.Length == 0) { throw new IndexOutOfRangeException("serial ports"); } var port = names[0]; this.Text = port; serialPort1.PortName = port; serialPort1.Open(); //timer1.Tick += timerTick; mmTimer = new MultimediaTimer(1); mmTimer.Elapsed += mmTimerTick; }