예제 #1
0
        public static bool AddEvent(DelayCallback cb, long time = 0, object[] param = null)
        {
            if (time <= 0)
            {
                cb(param);
                return true;
            }
            long lnNow = DelayEvent.GetCurUtcMSTime();

            SDCallbackInfo TimeCB = new SDCallbackInfo();
            TimeCB.nExecTime = lnNow + time;
            TimeCB.pCB = cb;
            TimeCB.Param = param;
            InsertAndSort(ref _delayEventList, TimeCB);
            //             _delayEventList.Add(TimeCB);
            //             _delayEventList.Sort(CompareTo);
            return true;
        }
예제 #2
0
 private static void InsertAndSort(ref List<SDCallbackInfo> list, SDCallbackInfo newSD)
 {
     SDCallbackInfo[] arrSD = list.ToArray();
     if (arrSD.Length == 0)
     {
         list.Add(newSD); return;
     }
     for (int i = 0; i < arrSD.Length; i++)
     {
         if (newSD.nExecTime < arrSD[i].nExecTime)
         {
             list.Insert(i, newSD);
             break;
         }
         if (i == arrSD.Length - 1)//队列里的都比新进入的小(新的应该放到最后一个)
         {
             list.Add(newSD);
         }
     }
 }
예제 #3
0
 private static int CompareTo(SDCallbackInfo a, SDCallbackInfo b)
 {
     int result;
     try
     {
         if (a.nExecTime > b.nExecTime)
         {
             result = 1;
         }
         else
             result = -1;
         return result;
     }
     catch (Exception ex) { throw new Exception(ex.Message); }
 }