private void btnStart_Click(object sender, EventArgs e) { if (isStart == false) { try { #region isStart = true; cmsgif = new CMessageInterface(); icrdOne = new ICCardReader(11, Convert.ToInt32(hall1Com)); icrdTwo = new ICCardReader(12, Convert.ToInt32(hall2Com)); icrdThree = new ICCardReader(13, Convert.ToInt32(hall3Com)); icrdFour = new ICCardReader(14, Convert.ToInt32(hall4Com)); //消息线程 try { DealMessageThread = new Thread(new ThreadStart(DealMessage)); DealMessageThread.Start(); } catch (Exception ex) { CWSException.WriteError("PLC线程启动异常:" + ex.ToString()); } //刷卡器1线程 try { ICCardH1Thread = new Thread(new ThreadStart(DealH1ICCardAction)); ICCardH1Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器1线程启动异常:" + ex.ToString()); } //刷卡器2线程 try { ICCardH2Thread = new Thread(new ThreadStart(DealH2ICCardAction)); ICCardH2Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器2线程启动异常:" + ex.ToString()); } //刷卡器3线程 try { ICCardH3Thread = new Thread(new ThreadStart(DealH3ICCardAction)); ICCardH3Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器3线程启动异常:" + ex.ToString()); } //刷卡器4线程 try { ICCardH4Thread = new Thread(new ThreadStart(DealH4ICCardAction)); ICCardH4Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器4线程启动异常:" + ex.ToString()); } //车厅1声音线程 try { SoundH1Thread = new Thread(new ThreadStart(DealHall1Sound)); SoundH1Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅1声音线程启动异常:" + ex.ToString()); } //车厅2声音线程 try { SoundH2Thread = new Thread(new ThreadStart(DealHall2Sound)); SoundH2Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅2声音线程启动异常:" + ex.ToString()); } //车厅3声音线程 try { SoundH3Thread = new Thread(new ThreadStart(DealHall3Sound)); SoundH3Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅3声音线程启动异常:" + ex.ToString()); } //车厅4声音线程 try { SoundH4Thread = new Thread(new ThreadStart(DealHall4Sound)); SoundH4Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅4声音线程启动异常:" + ex.ToString()); } //故障记录 try { LogThread = new Thread(new ThreadStart(DealRecordLog)); LogThread.Start(); } catch (Exception ex) { CWSException.WriteError("故障记录线程启动异常:" + ex.ToString()); } btnStop.Enabled = true; btnStart.Enabled = false; this.WindowState = FormWindowState.Minimized; #endregion } catch (Exception ex) { CWSException.WriteError("windows服务启动异常:" + ex.ToString()); } } }
protected override void OnStart(string[] args) { if (isStart == false) { #region isStart = true; cmsgif = new CMessageInterface(); icrdOne = new ICCardReader(11, Convert.ToInt32(hall1Com)); icrdTwo = new ICCardReader(12, Convert.ToInt32(hall2Com)); icrdThree = new ICCardReader(13, Convert.ToInt32(hall3Com)); icrdFour = new ICCardReader(14, Convert.ToInt32(hall4Com)); //消息线程 try { DealMessageThread = new Thread(new ThreadStart(DealMessage)); DealMessageThread.Start(); } catch (Exception ex) { CWSException.WriteError("PLC线程启动异常:" + ex.ToString()); } //刷卡器1线程 try { ICCardH1Thread = new Thread(new ThreadStart(DealH1ICCardAction)); ICCardH1Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器1线程启动异常:" + ex.ToString()); } //刷卡器2线程 try { ICCardH2Thread = new Thread(new ThreadStart(DealH2ICCardAction)); ICCardH2Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器2线程启动异常:" + ex.ToString()); } //刷卡器3线程 try { ICCardH3Thread = new Thread(new ThreadStart(DealH3ICCardAction)); ICCardH3Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器3线程启动异常:" + ex.ToString()); } //刷卡器4线程 try { ICCardH4Thread = new Thread(new ThreadStart(DealH4ICCardAction)); ICCardH4Thread.Start(); } catch (Exception ex) { CWSException.WriteError("刷卡器4线程启动异常:" + ex.ToString()); } //车厅1声音线程 try { SoundH1Thread = new Thread(new ThreadStart(DealHall1Sound)); SoundH1Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅1声音线程启动异常:" + ex.ToString()); } //车厅2声音线程 try { SoundH2Thread = new Thread(new ThreadStart(DealHall2Sound)); SoundH2Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅2声音线程启动异常:" + ex.ToString()); } //车厅3声音线程 try { SoundH3Thread = new Thread(new ThreadStart(DealHall3Sound)); SoundH3Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅3声音线程启动异常:" + ex.ToString()); } //车厅4声音线程 try { SoundH4Thread = new Thread(new ThreadStart(DealHall4Sound)); SoundH4Thread.Start(); } catch (Exception ex) { CWSException.WriteError("车厅4声音线程启动异常:" + ex.ToString()); } //故障记录 try { LogThread = new Thread(new ThreadStart(DealRecordLog)); LogThread.Start(); } catch (Exception ex) { CWSException.WriteError("故障记录线程启动异常:" + ex.ToString()); } CWSException.WriteLog("服务已经启动!", 4); #endregion } }