Ejemplo n.º 1
0
        /// <summary>
        /// 达到时间间隔时候触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            lock (removeList)
            {
                TimerModel tmpModel = null;
                foreach (var id in removeList)
                {
                    idModelDict.TryRemove(id, out tmpModel);
                }
                removeList.Clear();
            }

            foreach (var model in idModelDict.Values)
            {
                if (model.Time <= DateTime.Now.Ticks)
                {
                    model.Run();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加定时任务 指定延迟的时间 40s
        /// </summary>
        /// <param name="dateTime">毫秒!!!</param>
        /// <param name="timeDelegate"></param>
        public void AddTimeEvent(long dateTime, TimeDelegate timeDelegate)
        {
            TimerModel model = new TimerModel(id.Add_Get(), DateTime.Now.Ticks + dateTime, timeDelegate);

            idModelDict.TryAdd(model.Id, model);
        }