/// <summary> /// 将指定task入队 /// </summary> /// <param name="task"></param> public void Enqueue(RantaTaskBase task) { lock (lockObject) { taskList.Add(task); } }
/// <summary> /// 出队一个指定的task /// </summary> /// <returns></returns> public RantaTaskBase Dequeue() { lock (lockObject) { RantaTaskBase task = null; if (taskList.Count > 0) { task = taskList.First(); taskList.RemoveAt(0); } return(task); } }
/// <summary> /// 开始消费 /// </summary> public void Start() { workTask = new Task(() => { while (!stopConsume) { RantaTaskBase task = queue.Dequeue(); if (task != null) { task.Start(); } else { Thread.Sleep(500); } } }); workTask.Start(); }