views:

57

answers:

2

Hi,

Debugging a multithreaded app. I'm freezing threads as I see them created, but I wonder if there is a setting so that newly generated threads are suspended by default?

I keep glancing up and seeing new threads running which I don't want!

Thanks

+2  A: 

Set a breakpoint at the start of the thread procedure. Open the threading window so you can see all the running threads. You can simply click through the threads (and name them if you want to easily identify them).

P.Brian.Mackey
why the downvote?
P.Brian.Mackey
Compensation upvote. It doesn't hand the OP the solution but grasping at straws is appropriate here.
Hans Passant
lol, thanks Hans. You rock
P.Brian.Mackey
+4  A: 

No such option in Visual Studio. Just about the only thing you could do is calling a Thread object's Suspend() method right after creating it. This cannot work for threadpool threads.

The compiler is going to nag you when you do this, Suspend() is an obsolete method. It was abused back in the .NET 1.x days to synchronize threads, something it cannot do reliably. Which is of course exactly what you are doing. The particular problem you create by doing this is that you are just no longer debugging the app in a way that's at all representative for how it works in production. You'll hide threading race bugs.

Debugging threading bugs can be very difficult. Just about the only reasonable approach is using tracing. Which in itself changes code execution timing, making bugs disappear. After debugging this for a week or so, step back and ask yourself whether the program is using too many threads and has become unmaintainable.

Hans Passant
Cool. I thought as much. Feels like hearding cats!
BombDefused