Exemplo n.º 1
0
        public bool ReplaceTimeTask(int tid, Action <int> callback, float delay, ILTimerUnit timerUnit = ILTimerUnit.Millisecond, int count = 1)
        {
            if (timerUnit != ILTimerUnit.Millisecond)
            {
                switch (timerUnit)
                {
                case ILTimerUnit.Second:
                    delay = delay * 1000;
                    break;

                case ILTimerUnit.Mintue:
                    delay = delay * 1000 * 60;
                    break;

                case ILTimerUnit.Hour:
                    delay = delay * 1000 * 60 * 60;
                    break;

                case ILTimerUnit.Day:
                    delay = delay * 1000 * 60 * 60 * 24;
                    break;

                default:
                    LogInfo("Replace Task TimeUnit Type Error...");
                    break;
                }
            }

            nowTime = GetUTCMilliseconds();
            ILTimerTask newTask = new ILTimerTask(tid, callback, nowTime + delay, delay, count);

            bool isRep = false;

            for (int i = 0; i < taskTimeLst.Count; i++)
            {
                if (taskTimeLst[i].tid == tid)
                {
                    taskTimeLst[i] = newTask;
                    isRep          = true;
                    break;
                }
            }

            if (!isRep)
            {
                for (int i = 0; i < tmpTimeLst.Count; i++)
                {
                    if (tmpTimeLst[i].tid == tid)
                    {
                        tmpTimeLst[i] = newTask;
                        break;
                    }
                }
            }

            return(isRep);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加定时任务
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="delay"></param>
        /// <param name="timerUnit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public int AddTimeTask(Action <int> callback, double delay, ILTimerUnit timerUnit = ILTimerUnit.Millisecond, int count = 1)
        {
            if (timerUnit != ILTimerUnit.Millisecond)
            {
                switch (timerUnit)
                {
                case ILTimerUnit.Second:
                    delay = delay * 1000;
                    break;

                case ILTimerUnit.Mintue:
                    delay = delay * 1000 * 60;
                    break;

                case ILTimerUnit.Hour:
                    delay = delay * 1000 * 60 * 60;
                    break;

                case ILTimerUnit.Day:
                    delay = delay * 1000 * 60 * 60 * 24;
                    break;

                default:
                    LogInfo("Add Task TimeUnit Type Error...");
                    break;
                }
            }

            int tid = GetTid();

            nowTime = GetUTCMilliseconds();
            lock (lockTime)
            {
                tmpTimeLst.Add(new ILTimerTask(tid, callback, nowTime + delay, delay, count));
            }

            return(tid);
        }