예제 #1
0
 /// <summary>
 /// 将指定task入队
 /// </summary>
 /// <param name="task"></param>
 public void Enqueue(RantaTaskBase task)
 {
     lock (lockObject)
     {
         taskList.Add(task);
     }
 }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
        /// <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();
        }