C # thread monitoring - what does what / when

Like everything, I use to debug my code in VS in a step-by-step mode. Well, now that I have an application with many reference workers around the world, I am no longer in Kansas.

What is the most efficient way to debug streaming applications and the ability to track each thread to keep track of what is going on throughout the code?

At the moment, I stick to good debugging using separate log instances for each thread, but this is gradually becoming a nightmare, and I will soon drown in my logs.

+7
multithreading c #
source share
4 answers

Do not try to debug everything at once. Limit your attention to specific behavior in a single thread or pair of threads that interact around a mutex lock. If accessing the shared resource is a problem, set breakpoints around the use of that resource (which should be in the shared code, not everywhere).

If you just want thread 3 to be completed before thread 1 or this thread 2 has used all its work items and is sitting idle, use the logs for this.

You can also use the VS Threads view to see what each thread does when a process stops at any breakpoint on any thread. This may give you some idea of ​​what all threads are doing at any given time.

+8
source share

A little tip that can ease your pain is to use Visual Studio to freeze threads that you are not interested in. Then, when you tell the debugger to continue, frozen threads will never execute and will not hit breakpoints and confuse you.

Perhaps you can use this method to allow only debugged threads to work. For example. keep one thread in the queue and one thread that activates but freezes everything else.

You can freeze / thaw threads from the Thread Studio window by right-clicking on the thread.

+5
source share

Spell it right the first time.

The joke aside, the trick for debugging is to break it into manageable parts. Perform one work task at the same time, make sure that it does what it should have done.

Once you have done this, debugging problems in the main thread are much simpler because you can pretty much ignore background workers and just assume that they give the right results when they should be.

The only place that is more difficult to debug than a single-threaded application is the relationship between threads, which should not be much more difficult if you use libraries the way you should.

0
source share

I came across a detailed MSDN article on Debugging multithreaded applications which really helped. Thanx for all the previous answers that directed me on the right path.

0
source share

All Articles