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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.