using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace YG.Lib { /// /// 委托 /// /// /// public delegate bool queue_Delegate(object ob); /// /// 任务列表信息 /// public class Queue_Task_List { /// /// 任务标识符 /// public string queueID { get; set; } /// /// 委托对象的参数 /// public object ob { get; set; } /// /// 委托 /// public queue_Delegate QDTL { get; set; } } public class QueueLib { private static QueueLib qh = new QueueLib(); public static QueueLib Instance { get { return qh; } } /// /// 执行事件的列表 /// System.Collections.Concurrent.ConcurrentQueue qlist = new System.Collections.Concurrent.ConcurrentQueue(); /// /// 添加任务到列表信息中 /// /// /// public void Queue_Add(object ob, queue_Delegate qd) { qlist.Enqueue(new Queue_Task_List() { ob = ob, QDTL = qd }); } /// /// 弹出一个任务 /// /// /// public bool Queue_Dequeue(out Queue_Task_List qt) { qt = new Queue_Task_List(); if (qlist.Count > 0) { if (qlist.TryDequeue(out qt)) { return true; } else { return false; } } return false; } /// /// 查找任务 /// /// /// /// public bool Queue_Find(string id, Queue_Task_List qt) { try { Queue_Task_List ql = qlist.Where(m => m.queueID.Equals(id)).FirstOrDefault(); ql = qt; return true; } catch(Exception ex) { YG.Log.Instance.WriteLogAdd($"91-->{ex.Message}"); return false; } } public void Queue_Close() { // qlist. } } }