private void btnStart_Click(object sender, EventArgs e) { if (IsStartTest) { this.timer1.Stop(); this.timer1.Enabled = false; monitor.Close(); monitor.UnRegMonitor(this); monitor.HotKeyHandle = IntPtr.Zero; monitor.Dispose(); monitor = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.btnStart.Text = "开始检测"; this.comBoxType.Enabled = true; IsStartTest = false; } else { IsStartTest = true; this.btnStart.Text = "停止检测"; CheckConfig(); this.timer1.Enabled = true; this.timer1.Start(); this.comBoxType.Enabled = false; try { monitor = SignalMonitorFactory.CreateSignalMonitor(_monInfo, _currentSetup.Settings); monitor.HotKeyHandle = this.Handle; monitor.RegMonitor(this); monitor.Start(); } catch (InvalidCastException ice) { MessageBox.Show("Monitor与Setting不配套。", "错误!"); this.Close(); } } }
private void ExamFrm_FormClosing(object sender, FormClosingEventArgs e) { if (examCtrl.IsExaming) { if (this.IsExam) { MessageBox.Show("正在考试,不能退出。"); } else { MessageBox.Show("正在练习,不能退出。"); } e.Cancel = true; return; } if (mon != null) { mon.Close(); } if (displaycomm != null) { displaycomm.Close(); } }