public TimerTaskPool Preload(int count) { for (int i = 0; i < count; i++) { var t = new TimerTask(); ReleaseATimer(t); } return(this); }
public void ReturnToPool(TimerTask task) { //for (int i = 0; i < ReleaseList.Length; i++) //{ // var hand = ReleaseList[i]; // if (hand == null) // { // ReleaseList[i] = task; // return; // } //} }
/// <summary> /// 归还timer,如果塞不下,就不要了 /// </summary> /// <param name="tim"></param> public void ReleaseATimer(TimerTask tim) { tim.Clear(); for (int i = 0; i < EmptyTimerArr.Length; i++) { var t = EmptyTimerArr[i]; if (t == null) { EmptyTimerArr[i] = tim; return; } } }
/// <summary> /// 从池里拿个,如果没有就创个 /// </summary> /// <returns></returns> public TimerTask GetATimer() { for (int i = 0; i < EmptyTimerArr.Length; i++) { var t = EmptyTimerArr[i]; if (t != null) { EmptyTimerArr[i] = null; return(t); } } var item = new TimerTask(); return(item); }
public void RemoveUpdateTimer(TimerTask task) { //RemoveList.Remove(task); HandleList.Remove(task); }
public void AddUpdateTimer(TimerTask task) { // AddList.Add(task); HandleList.Add(task); }