Xaqron Xaqron - 8 days ago 5
C# Question

How to debug a single thread in Visual Studio?

I have a solution with some projects. There are several break-points in different projects. I want to trace the first thread hit one of these break-points and continue tracing that single thread despite of other threads entering the same code-blocks.

I know this is possible through defining a condition on the break-point, that is, thread name = ... or thread Id = ... but my case is a heavy loaded ASP.NET application and as soon as I attach to

w3wp.exe
many threads will hit the break-points. I need some thing like a
ThreadLocal<break-point>
.

Is it possible? If so, how?

Answer

Freeze/Thaw threads is an incorrect way because other threads don't execute any code.

The most correct and usable way is to:

  1. Hit Ctrl+A in the breakpoints window (select all breakpoints).
  2. Right click and select "Filter...".
  3. Enter "ThreadId=(current thread id)".

So all threads are executed, but the debugger hits on the current thread only.

Comments