/// <summary> /// Check if a stop is requested. /// </summary> /// <param name="msDelay"></param> /// <returns></returns> protected bool CheckStop(int msDelay) { ThreadStop.WaitOne(msDelay, false); ThreadStop.Reset(); return(StopFlag); }
/// <summary> /// Start the service. /// </summary> public void StartService() { if (_theThread == null) { _threadStop = new ManualResetEvent(false); _theThread = new Thread(delegate() { bool bInit = false; while (!bInit) { try { bInit = Initialize(); } catch (Exception e) { Platform.Log(LogLevel.Warn, e, "Unexpected exception intializing {0} service", Name); } if (!bInit) { // Wait before retrying init ThreadStop.WaitOne(ThreadRetryDelay, false); ThreadStop.Reset(); if (_stopFlag) { return; } } } if (_stopFlag) { return; } try { Run(); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception running service {0}", Name); } }); _theThread.Name = String.Format("{0}:{1}", Name, _theThread.ManagedThreadId); _theThread.Start(); } }