Esempio n. 1
0
 private void ThreadMns()
 {
     mns = new MNSService();
     try
     {
         mns.RunningState += mns_RunningState;
         th = new Thread(delegate()
         {
             try
             {
                 mns.isRunning = true;
                 mns.StartMns(ConfigurationManager.AppSettings["topicName"]);
             }
             catch (Exception err)
             {
                 LogHelper.Write("开始线程内部异常:" + err.Message + err.StackTrace);
             }
         });
         th.IsBackground = true;
         th.Start();
     }
     catch (Exception err)
     {
         //mns.isRunning = false;
         //MessageBox.Show(err.Message);
         //th.Abort();
         LogHelper.Write("ThreadMns开始线程异常:" + err.Message + err.StackTrace);
     }
 }
Esempio n. 2
0
 private void ThreadMonitor()
 {
     try
     {
         thMonitor = new Thread(delegate()
         {
             while (isMonitor)
             {
                 if (mns != null)
                 {
                     SetDelegateTime("监控时间:" + DateTime.Now.ToString() + "  ----  调度时间:" + mns.runCurrentDateTime.ToString());
                     TimeSpan ts = DateTime.Now - mns.runCurrentDateTime;
                     if (ts.TotalSeconds > 40)
                     {
                         try
                         {
                             if (th != null)
                             {
                                 th.Abort();
                                 th.Abort();
                                 th  = null;
                                 mns = null;
                             }
                             ThreadMns();
                         }
                         catch (Exception ex)
                         {
                             LogHelper.Write("111.ThreadMonitor监控线程异常:" + ex.Message + ex.StackTrace);
                         }
                     }
                     Thread.Sleep(1000);
                 }
             }
         });
         thMonitor.IsBackground = true;
         thMonitor.Name         = "监控线程";
         thMonitor.Start();
     }
     catch (Exception err)
     {
         LogHelper.Write("ThreadMonitor监控线程异常:" + err.Message + err.StackTrace);
     }
 }
Esempio n. 3
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                if (!isMonitor)
                {
                    ThreadMns();
                    ThreadMonitor();
                    isMonitor     = true;
                    btnStart.Text = "停止";
                }
                else
                {
                    isMonitor     = false;
                    btnStart.Text = "开始";

                    if (thMonitor != null)
                    {
                        thMonitor.Abort();
                        thMonitor = null;
                    }

                    if (mns != null)
                    {
                        mns.isRunning = false;
                    }
                    if (th != null)
                    {
                        th.Abort();
                        th  = null;
                        mns = null;
                    }
                }
            }
            catch (Exception err)
            {
                LogHelper.Write("开始按钮异常:" + err.Message + err.StackTrace);
                MessageBox.Show(err.Message);
            }
        }