Esempio n. 1
0
 private void timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     lock (mission)
     {
         lock (removelist)
         {
             foreach (int item in removelist)
             {
                 //mission.Remove(item);
                 TimeTaskModel model = null;
                 mission.TryRemove(item, out model);
             }
             removelist.Clear();
             foreach (TimeTaskModel item in mission.Values)
             {
                 long i = ((item.time - DateTime.Now.Ticks) / (1000 * 10000)) + 1;
                 if (item.time < DateTime.Now.Ticks)
                 {
                     item.run();
                     removelist.Add(item.id);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 微妙级时间轴
 /// </summary>
 /// <param name="task"></param>
 /// <param name="delay"></param>
 /// <returns></returns>
 /// DateTime.Now.Ticks
 public int schedulemms(TimeEvent task, long delay)
 {
     lock (mission)
     {
         int           id    = index.GetAdd();
         TimeTaskModel model = new TimeTaskModel(id, task, DateTime.Now.Ticks + delay);
         mission.TryAdd(id, model);
         return(id);
     }
 }