public bool ReplaceFrameTask(int tid, Action <int> callback, int delay, int count = 1) { WinterFrameTask newTask = new WinterFrameTask(tid, callback, frameCounter + delay, delay, count); bool isRep = false; for (int i = 0; i < taskFrameLst.Count; i++) { if (taskFrameLst[i].tid == tid) { taskFrameLst[i] = newTask; isRep = true; break; } } if (!isRep) { for (int i = 0; i < tmpFrameLst.Count; i++) { if (tmpFrameLst[i].tid == tid) { tmpFrameLst[i] = newTask; isRep = true; break; } } } return(isRep); }
private void DelFrameTask() { if (tmpDelFrameLst.Count > 0) { lock (lockFrame) { for (int i = 0; i < tmpDelFrameLst.Count; i++) { bool isDel = false; int delTid = tmpDelFrameLst[i]; for (int j = 0; j < taskFrameLst.Count; j++) { WinterFrameTask task = taskFrameLst[j]; if (task.tid == delTid) { isDel = true; taskFrameLst.RemoveAt(j); recTidLst.Add(delTid); break; } } if (isDel) { continue; } for (int j = 0; j < tmpFrameLst.Count; j++) { WinterFrameTask task = tmpFrameLst[j]; if (task.tid == delTid) { tmpFrameLst.RemoveAt(j); recTidLst.Add(delTid); break; } } } } } }
private void CheckFrameTask() { if (tmpFrameLst.Count > 0) { lock (lockFrame) { //加入缓存区中的定时任务 for (int tmpIndex = 0; tmpIndex < tmpFrameLst.Count; tmpIndex++) { taskFrameLst.Add(tmpFrameLst[tmpIndex]); } tmpFrameLst.Clear(); } } frameCounter += 1; //遍历检测任务是否达到条件 for (int index = 0; index < taskFrameLst.Count; index++) { WinterFrameTask task = taskFrameLst[index]; if (frameCounter < task.destFrame) { continue; } else { Action <int> cb = task.callback; try { if (taskHandle != null) { taskHandle(cb, task.tid); } else { if (cb != null) { cb(task.tid); } } } catch (Exception e) { LogInfo(e.ToString()); } //移除已经完成的任务 if (task.count == 1) { taskFrameLst.RemoveAt(index); index--; recTidLst.Add(task.tid); } else { if (task.count != 0) { task.count -= 1; } task.destFrame += task.delay; } } } }