Exemple #1
0
 public TaskFlag(TaskFlag flag, TaskType type)
 {
     id        = flag.id;
     index     = flag.index;
     this.type = type;
     active    = flag.active;
 }
Exemple #2
0
        private void RemoveFrameListItem(int index)
        {
            if (frameTaskList.Count == 0 && tempFrameTaskList.Count == 0)
            {
                return;
            }

            FrameTask task = frameTaskList[index];

            RemoveListItem_FrameTask(frameTaskList, index);
            if (index < frameTaskList.Count)
            {
                FrameTask indexTask = frameTaskList[index];
                TaskFlag  flag      = new TaskFlag
                {
                    id     = indexTask.id,
                    index  = index,
                    active = true
                };
                idDic[indexTask.id] = flag;
            }

            delIds.Add(task.id);
            //idDic.Remove(task.id);
        }
Exemple #3
0
 public TaskFlag(TaskFlag flag, bool active)
 {
     id          = flag.id;
     index       = flag.index;
     type        = flag.type;
     this.active = active;
 }
Exemple #4
0
        public IDPack AddFrameTask(Action <int> callBack, int delay, int count = 1)
        {
            int destFrame = sinceframeCount + delay;

            int id = GetId();

            if (id == -1)
            {
                return(new IDPack(id, TaskType.FrameTask));
            }

            idDic[id] = new TaskFlag(idDic[id], TaskType.FrameTask);
            FrameTask task = new FrameTask
            {
                id        = id,
                delay     = delay,
                destFrame = destFrame,
                callBack  = callBack,
                count     = count
            };

            lock (lockFrame)
            {
                tempFrameTaskList.Add(task);
            }

            return(new IDPack(id, TaskType.FrameTask));
        }
Exemple #5
0
        private void RemoveTimeListItem(int index)
        {
            if (timeTaskList.Count == 0 && tempTimeTaskList.Count == 0)
            {
                return;
            }

            TimeTask task = timeTaskList[index];

            RemoveListItem_TimeTask(timeTaskList, index);

            if (index < timeTaskList.Count)
            {
                TimeTask indexTask = timeTaskList[index];
                TaskFlag flag      = new TaskFlag
                {
                    id     = indexTask.id,
                    index  = index,
                    active = true
                };
                idDic[indexTask.id] = flag;
            }

            delIds.Add(task.id);
            //lock(lockId) idDic.Remove(task.id);
        }
Exemple #6
0
        private void AddFrameListItem(FrameTask task)
        {
            TaskFlag flag = new TaskFlag
            {
                id     = task.id,
                index  = frameTaskList.Count,
                active = true
            };

            idDic[task.id] = flag;
            frameTaskList.Add(task);
        }
Exemple #7
0
        public IDPack AddTimerTask(Action <int> callBack, double delay, int count = 1, TimeUnit unit = TimeUnit.Millisecound)
        {
            switch (unit)
            {
            case TimeUnit.Millisecound:
                break;

            case TimeUnit.Secound:
                delay *= 1000;
                break;

            case TimeUnit.Minute:
                delay *= 1000 * 60;
                break;

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

            case TimeUnit.Day:
                delay *= 1000 * 60 * 60 * 24;     // 最大支持 24天
                break;
            }
            nowTime = GetUTCMilliseconds();
            double destTime = nowTime + delay;

            int id = GetId();

            if (id == -1)
            {
                return(new IDPack(id, TaskType.TimeTask));
            }

            idDic[id] = new TaskFlag(idDic[id], TaskType.TimeTask);
            TimeTask task = new TimeTask
            {
                id       = id,
                delay    = delay,
                destTime = destTime,
                callBack = callBack,
                count    = count
            };

            lock (lockTime)
            {
                tempTimeTaskList.Add(task);
            }

            return(new IDPack(id, TaskType.TimeTask));
        }
Exemple #8
0
        private int GetId()
        {
            lock (lockId)
            {
                id += 1;

                int len = 0;
                while (true)
                {
                    if (id == int.MaxValue)
                    {
                        id = 0;
                    }

                    if (idDic.ContainsKey(id))
                    {
                        id++;
                    }
                    else
                    {
                        break;
                    }

                    len++;
                    if (len == int.MaxValue)
                    {
                        LogInfo("计时任务已满,无法添加任务", LogLevel.Error);
                        return(-1);
                    }
                }

                TaskFlag flag = new TaskFlag
                {
                    id     = id,
                    active = false
                };
                idDic.Add(id, flag);
            }

            return(id);
        }