示例#1
0
        /// <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);
        }
示例#2
0
        /// <summary>
        /// Stop the service.
        /// </summary>
        public void StopService()
        {
            _stopFlag = true;
            Stop();

            if (_theThread.IsAlive)
            {
                ThreadStop.Set();
                _theThread.Join();
                _theThread = null;
            }
        }
示例#3
0
        /// <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();
            }
        }
示例#4
0
 /// <summary>
 /// Stop the service.
 /// </summary>
 public void StopService()
 {
     StopFlag = true;
     ThreadStop.Set();
 }