views:

27

answers:

2

I'm quite new to the multithreading environment and I'm having trouble debugging an application which makes use of a threadpool created by the elapsed event in System.Timers.timer class. I have a breakpoint set inside a method which is called each time by the elapsed event, but Visual Studio's is jumping between lines of code because it is indicating the actions of the other threads.

How do I debug through a method, from start to finish on a particular thread without Visual Studio alerting me of other threads? Can Visual Studio stop all threads and let me debug from a chosen thread?

A: 

Check out Debugging Multithreaded Applications on MSDN

cxfx
A: 

It is possible to suspend other threads while debugging and let only the thread you care about run.

  • Open the Threads Window in Visual Studio (Debug -> Windows -> Threads)
  • Right click on any thread you don't want to run and select "Freeze"
  • Continue debugging.

Don't forget to unfreeze the threads when you are done debugging your particular thread.

JaredPar
It is still difficult to debug because the event keeps on spawning new threads and I would have to freeze as they come along . However I realised my current implementation is wrong because multiple threads can access the same method (same members) if computation time is longer than the set interval of the timer. I'm now using 'lock', saves a lot of stress with debug.
yeastbeast