Hidden Breakpoint Feature: Stepping in just one thread

So I was giving this demo the other day of some of our new concurrency features in the Orcas CTP and  I found this "new" feature for breakpoints. At least it was new for me. Sorry I'm a noob :)

The code was something like so:


  451         private void ComputePrimes_ThreadProc(object obj)

  452         {

  453             ThreadParams threadParams = (ThreadParams)obj; <- Breakpoint here


  455             // Go through our range, determining if a number is a prime

  456             for (int number = threadParams.lower; number <= threadParams.upper; number++)

  457             {

  458                 if (IsAPrime(number))

  459                 {

  460                     // Then add to our list

  461                     _primes.Add(number);

  462                 }

  463             }


  465         }



The problem I was trying to demonstrate, while stepping through some code, was a race condition occurring on a collection (one of our new features is supposed to help point this out). However, whenever I stepped, the other threads kept hitting the breakpoint, moving my ip indicator back to the breakpoint, and generally screwing stuff up.

Here's a screenshot of it in action (notice our new other thread indicators)

Yeah this is a pain. I want to just step in this first thread. I guess I could wait until the right thread gets to the breakpoint, then freeze everybody else. This doesn't seem to work though (mostly because of the internal state of the other threads)

But wait, there is a way to step in just this thread!  

Here's how:

  1. Right click on the breakpoint and select "Filter" from the list of options
  2. When the filter dialog appears, type in a filter condition. I used ThreadName=<my thread name>
  3. Click OK

Now when the breakpoint gets hit, only this thread will be in stepping mode. (Something else I learned, threads are in one of 3 states - stepping, running, or suspended)

So as you step, the IP indicator won't jump around.

Of course this then made me want more, but I'll leave that for another post.