Ejemplo n.º 1
0
 /// <summary>
 /// 开始处理队列内容
 /// </summary>
 /// <param name="database">数据库</param>
 /// <param name="t">返回内容(如果返回True)</param>
 /// <param name="waitMs">等待时长</param>
 public bool StartProcess(out string database, out List <EntityEventItem> t, int waitMs)
 {
     lock (Doing)
     {
         if (Doing.Count > 0)//之前存在失败
         {
             database = Doing.Peek();
             if (!DoItems.TryGetValue(database, out t))
             {
                 return(false);
             }
             if (t != null && t.Count != 0)
             {
                 return(true);
             }
             DoItems.Remove(database);
             t        = null;
             database = null;
             return(false);
         }
         if (!_semaphore.WaitOne(waitMs))
         {
             t        = null;
             database = null;
             return(false);
         }
         database = Queue.Dequeue();
         t        = Items[database];
         Items.Remove(database);
         if (t.Count == 0)
         {
             return(true);
         }
         Doing.Enqueue(database);
         if (DoItems.TryGetValue(database, out var list))
         {
             list.AddRange(t);
         }
         else
         {
             DoItems.Add(database, t);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 完成处理队列内容
 /// </summary>
 public void EndProcess()
 {
     lock (Doing)
     {
         var key = Doing.Dequeue();
         PubCount  += 1;
         DataCount += DoItems[key].Count;
         if (DataCount == long.MaxValue)
         {
             DataCount = 0;
         }
         if (PubCount == long.MaxValue)
         {
             PubCount = 0;
         }
         DoItems.Remove(key);
     }
 }