public virtual void Start() { //1.log start process _mesLog.LogInfo("***** " + this.Name + " thread started! *****"); //2.loop to upload _loopFlag = true; while (_loopFlag) { try { this.DoService(); _mesLog.LogInfo(this.Name + " processed one round completely."); Thread.Sleep(_loopPeriod); } catch (Exception ex) { _mesLog.LogException(ex.Message + Environment.NewLine + ex.StackTrace, this.Name + ".DoService"); } } // time to end the thread if (Thread.CurrentThread.ThreadState != ThreadState.Aborted) { Thread.CurrentThread.Abort(); _mesLog.LogInfo("***** " + this.Name + " thread to abort! *****"); } }
public bool Run() { if (_services != null && _services.Count > 0) { foreach (IService service in _services) { try { Thread thread = new Thread(new ThreadStart(service.Start)); thread.Name = service.Name; thread.Start(); _dataLog.LogInfo("***** " + service.Name + " started! *****"); // _threads.Add(thread); } catch (Exception ex) { _dataLog.LogException(ex.Message + Environment.NewLine + ex.StackTrace, service.Name + ".Run"); } } } return(true); }