Parallel.ForEach - Access To Modified Closure Applies?

后端 未结 2 433
南旧
南旧 2021-01-14 00:57

I\'ve read a number of other questions about Access to Modified closure so I understand the basic principle. Still, I couldn\'t tell - does Parallel.ForEach hav

2条回答
  •  情深已故
    2021-01-14 01:30

    You are accessing a modified closure, so it does apply. But, you are not changing its value while you are using it, so assuming you are not changing the values inside UpdateUsageStats you don't have a problem here.

    Parallel.Foreach waits for the execution to end, and only then are you changing the values in startTime and endTime.

提交回复
热议问题