Beispiel #1
0
        //添加定时任务 XX时间后执行
        public void AddTimeEvent(long delayTime, int userId, TimeOutDelegate timeOutDelegate)
        {
            Console.WriteLine("add timeout event   " + userId);
            TimeOutModel model = new TimeOutModel(id.Add_Get(), userId, DateTime.Now.Ticks + delayTime, timeOutDelegate);

            idModelDict.TryAdd(model.Id, model);
        }
Beispiel #2
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            lock (removeList)
            {
                TimeOutModel tempModel = null;
                foreach (var id in removeList)
                {
                    idModelDict.TryRemove(id, out tempModel);
                }
                removeList.Clear();
            }

            foreach (var model in idModelDict.Values)
            {
                if (model.Time <= DateTime.Now.Ticks)
                {
                    model.Run();
                }
            }
        }