示例#1
0
 public void Execute()
 {
     lock (sync)
     {
         var oCount = Items.Count;
         for (int i = 0; i < oCount; i++)
         {
             ThreadItem item = Items.Dequeue();
             item.Invoke();
         }
     }
 }
示例#2
0
        private void StartThread(ThreadItem task)
        {
            _threads.Add(task);
            BackgroundWorker thread = new BackgroundWorker();

            thread.DoWork += delegate
            {
                task.Invoke();
            };
            thread.RunWorkerCompleted += delegate
            {
                _threads.Remove(task);

                CheckQueue();

                if (_queue.Count == 0 && _threads.Count == 0 && RaiseCompleteEventIfQueueEmpty)
                {
                    OnCompleted();
                }
            };
            thread.RunWorkerAsync();
        }