Groups | Blog | Home
all groups > visual studio .net debugging > january 2004 >

visual studio .net debugging : debugging multi threads


Bob Day
1/26/2004 11:59:33 AM
Using XP Pro, VS 2003, VB.NET, MSDE...

Can you point me to a URL that describes best practices for debuging
multiple threads in a winform application? I have some bugs, that only
exits when running multiple threads, I am not excactly sure what the best
approach is to tackling the problem.

Addtionally, in my search of MSDN I came up with several items concering
debugging that I don't completely understand.

Are the following 'debuggers' needed or is there functionality, more or
less, already incorporated in VS 2003? I think there functionality is
already incomporated, since the article indicated they would be in future
releases of VS, but I could tell what version they were on when they said
that? I have down loaded them (download file dbg_x86_6.3.5.exe), but have
not installed them pending your answer. Also, a good URL giving an overview
of what they add to VS 2003 debugging functionality would be helpful (if
needed at all)
CorDbg, WinDbg, WinDbg and SOS

Also, Windows Symbols for debugging. I have downloaded the file
(xpsplsym_x86.exe), but not yet installed it. I don't follow what the
sysmbols are for, and if their funcitonality is alreadin VS 2003. My
soltuion's Property Pages does have two path for Symbols Files. What are
they, how are they used? A good URL summary would be helpful

Thanks!

Bob Day



timhuang NO[at]SPAM online.microsoft.com
1/27/2004 2:53:59 AM
Hello Bob,

Thanks for your post. As I understand, you have some problems in a
multi-threaded WinForm application and want to locate them. Now I'd like to
share the following information with you:

1. Please make sure that you did not a control's method directly from
another thread. As you know, Windows Forms uses the single-threaded
apartment (STA) model because Windows Forms is based on native Win32
windows that are inherently apartment-threaded. The STA model implies that
a window can be created on any thread, but it cannot switch threads once
created, and all function calls to it must occur on its creation thread.

There are four methods on a control that are safe to call from any thread:
Invoke, BeginInvoke, EndInvoke, and CreateGraphics. For all other method
calls, you should use one of the invoke methods to marshal the call to the
control's thread.

I believe the following articles are helpful:

Safe, Simple Multithreading in Windows Forms, Part 1
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm
l/winforms06112002.asp

Safe, Simple Multithreading in Windows Forms, Part 2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm
l/winforms08162002.asp

2. Another common issue in multi-threaded program is to synchronize threads
for protecting the shared resource. You can use Tracing/Logging machanism
to locate the problem in multi-threaded applicaitons.

Multithreaded Programming with Visual Basic .NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechar
t/html/vbtchasyncprocvb.asp

Visual Basic .NET: Tracing, Logging, and Threading Made Easy with .NET
http://msdn.microsoft.com/msdnmag/issues/01/07/vbnet/default.aspx

3. Based on my experience, there is nothing special when debugging
multi-threaded application and I believe the Tracing/Logging machanism is
very helpful. The following KB article contains most information on .NET
Debugging:

INFO: Roadmap for Debugging in .NET Framework and Visual Studio .NET
http://support.microsoft.com/?id=308626

4. Generally speaking, VS .NET Debugger is enough for debugging user-mode
application. If you want to debug low level applications say, Windows
Device Driver, you will need other debuggers (for example WinDbg).

There is also no need to install Windows Symbols for debugging
multi-threaded WinForm application. The following KB article describes the
symbol files (PDB and DBG files) in detail:

INFO: PDB and DBG Files - What They Are and How They Work
http://support.microsoft.com/default.aspx?scid=kb;EN-US;121366

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button