Example #1
0
        /// <summary>
        /// 停止服务运行
        /// 停止计时器并释放计时器资源
        /// 从列表中移除
        /// </summary>
        /// <param name="clocker"></param>
        public void Stop(Clocker clocker)
        {
            if (null != clocker)
            {
                lock (ClockerList)
                {
                    clocker.RunningTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    clocker.RunningTimer.Dispose();

                    if (ClockerList.Contains(clocker))
                    {
                        ClockerList.Remove(clocker);
                    }

                    ClockerList.TrimExcess();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 添加一个服务运行计时器
        /// </summary>
        /// <param name="clocker"></param>
        public void Add(Clocker clocker)
        {
            if (null == clocker)
            {
                return;
            }

            lock (ClockerList)
            {
                if (ClockerList == null)
                {
                    ClockerList = new List <Clocker>();
                }

                if (!ClockerKeys.Contains(clocker.Key))
                {
                    ClockerList.Add(clocker);
                }

                ClockerList.TrimExcess();
            }
        }