Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
3.22/5 (3 votes)
See more:
Hi I have a windows application which uses a opensource library having multiple threads (asterisk.net) But when i step into the code while debugging, the execution line changes between threads. This makes me difficult to debug. How can I make it to go line by line ?
Posted
Comments
[no name] 25-May-14 11:02am    
Looking also forwards to some tips. Have similar problems ;)

You can achieve this by using the Threads window while debugging. If you want to switch to a thread, right-click on the desired thread and click "Switch To Thread". If you cannot find your thread, then give it a name to find it faster:
C#
yourThread.Name = "Thread Name";

Now, the thread appears in the Threads window with this name.

If you don't want to switch to threads, you can freeze the threads that you don't need by right-clicking on a thread (or selecting multiple threads and right-clicking) and choosing "Freeze". If you don't longer want to freeze it, choose "Thaw". Note that freezing a thread means that it doesn't run, so if you want to synchronize data between threads, don't use Freeze.
 
Share this answer
 
Keep debugging with "difficulties"; it would be the best advice. Just debugging, with a single thread, also seemed difficult at first, right? But you used to it. Same thing with multi-threading debugging.

You should also understand that if you have problems with the design of multi-threading code, you won't be able to locate the using debugging. Same goes about testing. You design should be theoretically validated. One of the reasons for that is this: the code could have race conditions, which means incorrect dependency on the order of execution. When you debug such code, you strongly delay one thread relative to another one, and the order of operations changes, so the code won't behave the same was as without the debugger. Please see:
http://en.wikipedia.org/wiki/Race_condition[^].

Worse, due to race conditions, you can have the code which only seems to behave correctly, but will fail eventually (say, when the application is already deployed to the customer :-)). The failure can be as bad as it can possibly be, such as, for example, a deadlock or something else.

At the same time, wide class of applications can be build based on simple well-known patterns of threading which never fail. This is all the matter of knowledge and experience.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900