473,756 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debugging a multithreaded app in C#.



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
Nov 15 '05 #1
3 6027
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
"Developmen t" <De*********@sa torigroupinc.co m> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..


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

Nov 15 '05 #2
In article <uW************ **@TK2MSFTNGP10 .phx.gbl>, William Ryan wrote:
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

Nov 15 '05 #3
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: "Developmen t" <De*********@sa torigroupinc.co m>
!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: <#V************ **@tk2msftngp13 .phx.gbl>
!Newsgroups:
microsoft.publi c.dotnet.langua ges.csharp,micr osoft.public.vs net.debugging
!NNTP-Posting-Host: 207.106.112.178
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.vsnet.debuggi ng:3812
microsoft.publi c.dotnet.langua ges.csharp:1921 53
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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
!
!
!

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2983
by: Elbert Lev | last post by:
I started with Python two weeks ago and already saved some time and efforts while writing 2 programs: 1. database extraction and backup tool, which runs once a month and creates a snapshot of important data, compresses and saves it. 2. pop3 "watchdog", which reads e-mail from a pop3 mailbox and in the case there is no mail sends e-mail messages to technicians. (the presence of e-mail in the mailbox tells that the system I'm monitoring...
2
1945
by: Thomas Lindgaard | last post by:
Hello I have a multi-threaded web spider and it has a problem (probably several). Is there a way to make the debugger show me what my worker threads are doing? I can only get it to follow the main thread. I'm using Komodo Personal (trial). -- Regards /Thomas
2
6641
by: pradyumna | last post by:
In Project settins - C/C++ - Code Generation, what is the difference between the option "Multithreaded" and "Multithreaded DLL". I understand that on selecting multithreaded option, single and multithreaded applications can both use that dll, but what about multithreaded DLL option. Thanks
4
1329
by: Bruno van Dooren | last post by:
Hi, i was debugging a multithreaded app, when i stumbled across some weird behavior of the debugger. in the destructor of my main object i send a stop event to the worker thread, and then wait until that thread has finished. m_Stop = true; while(GetExitCodeThread() == STILL_RUNNING)
3
2601
by: groups | last post by:
Hi all, I've recently ported a rather large C application to run multithreaded. A few functions have seriously deteriorated in performance, in particular when accessing a rather large global array, that contains information that is shared among threads. Any idea, why the lines accessing this global array now take about 50x longer in the multithreaded application?
3
1665
by: | last post by:
Is it possible to have just a multithreaded sub procedure? What I need is a timer time_elapsed event (2 sec interval) send params to a sub that is multithreaded. I have a COM component used to send messages,faxes, etc.. The COM com component is licensed for 6 ports. I have an app that need to send messages/faxes very frequently (seconds) and to many, many people. What I want to do is have a sub that has 6 threads to send thse messages...
3
4599
by: Jake K | last post by:
I have a multithreaded application that I now want to convert into a Windows Service. Does application.run work in a windows service? Are there things to take into consideration when creating a multithreaded windows service as opposed to a multithreaded windows forms application? E.G. namespace whatever {
5
6396
by: John Henry | last post by:
I am back against the wall trying to migrate my multithreaded application from Python 2.3 to 2.5. The part of the code that's failing has to do with queues (2.3 queues and 2.5 queues are not the same). Since WingIDE doesn't support multithread debugging (they've been saying that one day they might support that - and that was 2003), I am starting to look for alternatives. debug under Eclipse/Pydev. I did a google search of this...
33
2884
by: fmassei | last post by:
Hello! I made a short piece of code that I find very useful for debugging, and I wanted to ask you if it is correct, somehow acceptable or if I simply reinvented the wheel. To deal with some bad bugs caused by memory leaks I ended up with this simple solution: I made one header file that, when included, replaces the malloc/calloc/realloc/free functions with some other functions that do the actual job and insert (or remove) the pointers to...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.