Как правильно сделать Parallel.ForEach, блокировки и отчеты о проделанной работе

я пытаюсь реализоватьParallel.ForEach шаблон и отслеживать прогресс, но яЯ что-то упускаю из-за блокировки. В следующем примере считается до 1000, когдаthreadCount = 1, но не когдаthreadCount > 1. Как правильно это сделать?

class Program
{
   static void Main()
   {
      var progress = new Progress();
      var ids = Enumerable.Range(1, 10000);
      var threadCount = 2;

      Parallel.ForEach(ids, new ParallelOptions { MaxDegreeOfParallelism = threadCount }, id => { progress.CurrentCount++; });

      Console.WriteLine("Threads: {0}, Count: {1}", threadCount, progress.CurrentCount);
      Console.ReadKey();
   }
}

internal class Progress
{
   private Object _lock = new Object();
   private int _currentCount;
   public int CurrentCount
   {
      get
      {
         lock (_lock)
         {
            return _currentCount;
         }
      }
      set
      {
         lock (_lock)
         {
            _currentCount = value;
         }
      }
   }
}

Ответы на вопрос(6)

Ваш ответ на вопрос