示例#1
0
 /// <summary>The stop.</summary>
 public void Stop()
 {
     this.Status = HelperServiceStatus.Stopping;
 }
示例#2
0
        /// <summary>The start.</summary>
        public void Start()
        {
            var delay = TimeSpan.FromHours(3);
            var delayStep = TimeSpan.FromSeconds(5);

            this.Status = HelperServiceStatus.Running;
            ThreadPool.QueueUserWorkItem(
                o =>
                    {
                        AppUtil.NameCurrentThread(this.GetType().Name + "-BGCurrencyData");
                        while (this.Status == HelperServiceStatus.Running)
                        {
                            cacheLock.EnterWriteLock();
                            try
                            {
                                LoadData();
                            }
                            catch (Exception ex)
                            {
                                this.Logger.Error(ex.Message);
                            }
                            finally
                            {
                                cacheLock.ExitWriteLock();
                            }

                            TimeSpan slept = TimeSpan.Zero;
                            while (slept < delay)
                            {
                                if (this.Status != HelperServiceStatus.Running)
                                {
                                    // Stop the delay if the service is no longer running
                                    break;
                                }

                                Thread.Sleep(delayStep);
                                slept += delayStep;
                            }
                        }

                        this.Status = HelperServiceStatus.Stopped;
                    });
        }