Debugging a multithreaded app in C#.

  • Thread starter Thread starter Development
  • Start date Start date
D

Development

I am creating 10 threads that do ecatly the same thing. I am having a very
hard time debugging this scenario. It seems that by default when you are
doing f10 or f11 all threads execute. You can see that by watching the
thread window. When you freeze all threads but the one you are working on
it then does not do anything.



So does anybody have any experience debugging multithreaded apps in C# and
could they share the best practices.

Genna
 
John Robbins book Debugging Applications for .NET and Windows has some
excellent strategies, and if you don't have the book, you'll definitely want
it. It really depends on what you want to do, but I would suggest using the
debug.Writeline and Throw a bunch of Debug.Assert in there. Debugging
multithreaded apps can be quite dreadful b/c things aren't happening in a
linear fashion, but you can still get a lot of feedback from the debugger.

HTH,

Bill
 
Debugging
multithreaded apps can be quite dreadful b/c things aren't happening in a
linear fashion, but you can still get a lot of feedback from the debugger.

I'm trying to debug a multi-threaded application, I think I understand the
cause of the problem but don't understand what the debugger is doing. Can
you help me understand the later.

My Windows Forms application has a UI that allows the user to start
activities that may take a while to complete. What I did was to have the UI
spin off a thread to handle this work. My first attempt had this thread try
to obtain a value from a textBox. At this point basically everything to do
with the application stopped and I would need to restart the app under the
debugger. While trouble shooting, I set a breakpoint at the beginning of the
worker thread. I had a watch window showing the textBox.

I noticed that when the breakpoint was reached, the textBox showed the
expected value for a few seconds and then, when the debug window enabled
show current statement, step over, etc. that the text box value disappeared
and its class name was shown instead.

Is this effect just a subtle way of letting me know that I shouldn't try to
access the control from the current thread or is there something else going
on?

Mike Blake-Knox
 
Hello Genna,

Thanks for posting in the group.

I noticed that the same question is also posted in VSNET.debugging group. I
replied you there. If you have time, please check my reply and post there
if there are any questions on it.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Development" <[email protected]>
!Subject: Debugging a multithreaded app in C#.
!Date: Fri, 17 Oct 2003 14:04:03 -0400
!Lines: 16
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <#[email protected]>
!Newsgroups:
microsoft.public.dotnet.languages.csharp,microsoft.public.vsnet.debugging
!NNTP-Posting-Host: 207.106.112.178
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.vsnet.debugging:3812
microsoft.public.dotnet.languages.csharp:192153
!X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
!
!
!
!I am creating 10 threads that do ecatly the same thing. I am having a
very
!hard time debugging this scenario. It seems that by default when you are
!doing f10 or f11 all threads execute. You can see that by watching the
!thread window. When you freeze all threads but the one you are working on
!it then does not do anything.
!
!
!
!So does anybody have any experience debugging multithreaded apps in C# and
!could they share the best practices.
!
!Genna
!
!
!
 
Back
Top