How to do proper Parallel.ForEach, locking and progress reporting

后端 未结 6 1262
小鲜肉
小鲜肉 2020-12-17 18:48

I\'m trying to implement the Parallel.ForEach pattern and track progress, but I\'m missing something regarding locking. The following example counts to 1000 whe

6条回答
  •  误落风尘
    2020-12-17 18:58

    Old question, but I think there is a better answer.

    You can report progress using Interlocked.Increment(ref progress) that way you do not have to worry about locking the write operation to progress.

提交回复
热议问题