private static void Working() { while (true && _workNotOver) { try { if (QueueTasks.Count == 0) { QueueTaskEvent.WaitOne(); continue; } IQueueTask task = null; lock (_lockDequeue) { //这边有可能拿到0数量 if (QueueTasks.Count == 0) continue; task = QueueTasks.Dequeue(); } task.Do(); } catch (Exception exp) { HZLogger.Error(string.Format("队列任务处理发生异常 {0}", JsonConvert.SerializeObject(exp))); } } }
public void Do() { string message = string.Empty; try { message = string.Format(" QueueTask Done. Data:{0}", this.Data); HZLogger.Info(message); } catch (FormatException exp) { HZLogger.Error(exp); } catch (Exception exp) { HZLogger.Error(exp); } }