Пример #1
0
 static void DoWork()
 {
     while (true)
     {
         ECItem work = null;
         lock (_locker)
         {
             if (_tasks.Count > 0)
             {
                 work = _tasks.Dequeue();
                 if (work == null)         //退出机制,当遇到一个null任务时,代表任务的结束
                 {
                     return;
                 }
             }
         }
         if (work != null)
         {
             UploadEyeImage(work.eyeFileName, work.eyeImgWidth, work.eyeImgHeight);
             UploadFaceImage(work.faceFileName, work.id, work.dateTime);
         }
         else
         {
             _wh.WaitOne();  //如果没有任务了,等待信号
         }
     }
 }
Пример #2
0
 public static void EnqueueTask(ECItem task)
 {
     lock (_locker)
     {
         if (boolThreadStart == false)
         {
             _worker = new Thread(DoWork);
             _worker.Start();
         }
         if (_tasks.Count < 5000)           //缓冲队列5000条
         {
             _tasks.Enqueue(task);
         }
     }
     _wh.Set();   //给工作线程发开始信号
 }