Search code examples
c#debuggingparallel.foreach

Parallel.ForEach Debug or Step Through


Is there an easy way to step through a parallel.foreach? What is the best way to debug this with a break point?


Solution

  • You can actually get similar results with Visual Studio just by freezing all the threads except one, select all threads but one in the Threads windows and right click -> Freeze like this:

    enter image description here

    Also, if you want to reproduce a race condition and stopping on breakpoints breaks it, you can always add tracepoints - either with visual studio or with plugins that help with it, such as Oz Code

    enter image description here