Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggestions for debugging a multithreaded app

I have problems with step-by-step debugging of a multithreaded .NET application in Visual Studio 2008.

With each stepped line, Visual Studio gets slower and slower (it takes more and more time to jump to the next line) and usually hangs after several lines (I get the "Visual Studio is busy" balloon tip), and I need to stop debugging.

I suspect the problem is due to the fact that application has several TCP/IP clients connected, which means that every time I make a breakpoint, their network buffer gets filled until I continue my application. Whenever I use F10 to step over to the next line of code, Visual Studio shortly awakens all other threads for them to handle the input data.

Does anyone have experience with such problems, and suggestions on how to avoid them?

like image 973
Groo Avatar asked Jul 25 '11 07:07

Groo


1 Answers

This is not an easy task at all, I believe you understand this. So very important to have a clear understanding of threading and synchronization mechanisms which are provided by .NET Framework. Only after doing this you can start designing a thread synchronisation and management.

I would suggest to define clear names for your threads and introduce extensive logging, log4net would be a good choice because provides you a thread safe and robust logging instruments.

Visual Studio tips:

  • How to: Use the Threads Window
  • How to: Switch to Another Thread While Debugging
  • How to: Flag and Unflag Threads

See more here: Debugging Multithreaded Applications

EDIT: Added more tips

Try to identify which application logic states really useful to be debugged manually and use conditional breakpoints if it is possible so you can avoid extra breaks of debugger:

  • How to: Specify a Breakpoint Condition
like image 70
sll Avatar answered Sep 17 '22 03:09

sll