public void Execute()
 {
     lock (sync)
     {
         var oCount = Items.Count;
         for (int i = 0; i < oCount; i++)
         {
             ThreadItem item = Items.Dequeue();
             item.Invoke();
         }
     }
 }
Beispiel #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();
        }