Debugging thread problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Brown

    Debugging thread problem

    Hi there,

    Has anyone had any problems debugging a thread in VS 2005. If I put a
    breakpoint on a worker thread (the only one in the app) and then run the app
    two things happen:

    1) It takes an unusually long time for the breakpoint to kick in once
    encountered
    2) When it finally does break, I can't step through any code. As soon as I
    try, the debugger just runs off somewhere and never returns control to me.

    Any suggestions? Thanks..


  • John Brown

    #2
    Re: Debugging thread problem

    Update:

    Unless there's some way to corrupt memory in C#/.NET (I'm relatively new to
    it but very experienced in C/C++), this appears to be a VS bug though any
    feedback would still be appreciated. That is, if I situate my breakpoint
    earlier in the code I can debug no problem. If I then move the breakpoint
    ahead one line at time, I eventually reach a point where the problem
    suddenly surfaces. This occurs when I move the breakpoint to the first line
    of a function outside the file where the thread actually starts. As soon as
    I try to step into that function, the debugger takes about 20 seconds to do
    so and when it finally does break, I can no longer step at all since the
    debugger never returns. At one point I did notice a very brief message flash
    on the bottom of the screen (in a small yellow window) to the effect that VS
    was waiting for some internal operation to finish or something like that (it
    flashed too quicly too digest it all). Anyway, this is a serious problem if
    I can't debug my thread so any input would be welcome. Thanks.


    Comment

    • Willy Denoyette [MVP]

      #3
      Re: Debugging thread problem


      "John Brown" <no_spam@_nospa m.comwrote in message
      news:Od8TEZE2GH A.1288@TK2MSFTN GP03.phx.gbl...
      | Hi there,
      |
      | Has anyone had any problems debugging a thread in VS 2005. If I put a
      | breakpoint on a worker thread (the only one in the app) and then run the
      app
      | two things happen:
      |
      | 1) It takes an unusually long time for the breakpoint to kick in once
      | encountered
      | 2) When it finally does break, I can't step through any code. As soon as I
      | try, the debugger just runs off somewhere and never returns control to me.
      |
      | Any suggestions? Thanks..
      |
      |

      What kind of application is this? Windows forms or console like.
      If Windows forms, do you pass the form object to the other thread?

      Willy.


      Comment

      • John Brown

        #4
        Re: Debugging thread problem

        What kind of application is this? Windows forms or console like.
        If Windows forms, do you pass the form object to the other thread?
        Well, the worker thread's main function (entry point) is a member of a
        "Form" derivative and it passes a reference to the enclosing object (form)
        to a function in another file and that's exactly where things start failing
        (as soon as the latter function is called). However, note that all GUI
        processing is being routed back to the main GUI thread via
        "Control.Invoke ()". In any case, is there a reason it should fail as soon
        that function is called (perhaps you're alluding to some marshalling issue I
        haven't considered - does the form's reference need to be marshalled to the
        thread in some way). Thanks for your assistance (appreciated).


        Comment

        • Samuel R. Neff

          #5
          Re: Debugging thread problem


          I've noticed this problem when stepping from code we have source for
          to code we don't have source for (a 3rd party dll) when the other code
          was compiled width debugging enabled. I most often run into this when
          debugging unit tests and I step past the end of one test and control
          returns to the test framework.

          Does the problem occur always on a particular line of code? What
          happens if instead of stepping into this line you step over it? Can
          you set a breakpoint later in the program and it works ok (past the
          offending line)?

          Sam



          ------------------------------------------------------------
          We're hiring! B-Line Medical is seeking Mid/Sr. .NET
          Developers for exciting positions in medical product
          development in MD/DC. Work with a variety of technologies
          in a relaxed team environment. See ads on Dice.com.




          On Thu, 14 Sep 2006 18:07:36 -0400, "John Brown" <no_spam@_nospa m.com>
          wrote:
          >Update:
          >
          >Unless there's some way to corrupt memory in C#/.NET (I'm relatively new to
          >it but very experienced in C/C++), this appears to be a VS bug though any
          >feedback would still be appreciated. That is, if I situate my breakpoint
          >earlier in the code I can debug no problem. If I then move the breakpoint
          >ahead one line at time, I eventually reach a point where the problem
          >suddenly surfaces. This occurs when I move the breakpoint to the first line
          >of a function outside the file where the thread actually starts. As soon as
          >I try to step into that function, the debugger takes about 20 seconds to do
          >so and when it finally does break, I can no longer step at all since the
          >debugger never returns. At one point I did notice a very brief message flash
          >on the bottom of the screen (in a small yellow window) to the effect that VS
          >was waiting for some internal operation to finish or something like that (it
          >flashed too quicly too digest it all). Anyway, this is a serious problem if
          >I can't debug my thread so any input would be welcome. Thanks.
          >

          Comment

          • John Brown

            #6
            Re: Debugging thread problem

            I've noticed this problem when stepping from code we have source for
            to code we don't have source for (a 3rd party dll) when the other code
            was compiled width debugging enabled. I most often run into this when
            debugging unit tests and I step past the end of one test and control
            returns to the test framework.
            >
            Does the problem occur always on a particular line of code? What
            happens if instead of stepping into this line you step over it? Can
            you set a breakpoint later in the program and it works ok (past the
            offending line)?
            I can step all over the function in file 1 anyway I like but as soon as I
            call a function in file 2 the problem starts (I own all source). Willy may
            be on to something however since I just discovered that the problem stops
            when I pass "null" to the offending function in file 2 instead of the "Form"
            reference I normally pass. I think there may be some marshalling issue here
            perhaps (with the form's reference). The situation is quite simple however.
            A form starts the worker thread going in its "OnLoad()" handler by invoking
            "BackgroundWork er.RunWorkerAsy nc()" (standard 2.0 class). The worker thread
            (another function in the form's class) then passes "this" to a function in
            another file. That's when all the trouble starts. The debugger goes away for
            a 20 second smoke (or whatever it's doing) and then it finally breaks at the
            first line in the latter function. At this point however I can't step any
            further without the debugger going into la la land permanently. Passing
            "null" instead of "this" however eliminates the problem. I thought that
            perhaps instead of passing "this", maybe I need to marshal the form's
            pointer to the thread somehow but if so then it's news to me (I'm relatively
            new to C# and .NET though very experienced in C/C++). Any thoughts?


            Comment

            • John Brown

              #7
              Re: Debugging thread problem

              >What kind of application is this? Windows forms or console like.
              >If Windows forms, do you pass the form object to the other thread?
              >
              Well, the worker thread's main function (entry point) is a member of a
              "Form" derivative and it passes a reference to the enclosing object (form)
              to a function in another file and that's exactly where things start
              failing (as soon as the latter function is called). However, note that all
              GUI processing is being routed back to the main GUI thread via
              "Control.Invoke ()". In any case, is there a reason it should fail as soon
              that function is called (perhaps you're alluding to some marshalling issue
              I haven't considered - does the form's reference need to be marshalled to
              the thread in some way). Thanks for your assistance (appreciated).
              By sheer coincidence I came across the following link while pursuing another
              matter related to this problem (what luck!). I'm still tinkering but the
              "DebuggerDispla y" attribute seems to have solved the problem for the moment.
              See the "System.Windows .Forms.Form and multithreading" section here:




              Comment

              • Cor Ligthert [MVP]

                #8
                Re: Debugging thread problem

                John,

                Although in VB.Net do I have the same problem. I hope that this is one of
                the fixes done in the next service pack, because this makes multithreading
                not fine to use at the moment in my idea. My screen is completely blanked
                out in those cases.

                (The Microsoft development debugger team is AFAIK the same for C# and
                VB.Net).

                Cor

                "John Brown" <no_spam@_nospa m.comschreef in bericht
                news:Od8TEZE2GH A.1288@TK2MSFTN GP03.phx.gbl...
                Hi there,
                >
                Has anyone had any problems debugging a thread in VS 2005. If I put a
                breakpoint on a worker thread (the only one in the app) and then run the
                app two things happen:
                >
                1) It takes an unusually long time for the breakpoint to kick in once
                encountered
                2) When it finally does break, I can't step through any code. As soon as I
                try, the debugger just runs off somewhere and never returns control to me.
                >
                Any suggestions? Thanks..
                >

                Comment

                • Willy Denoyette [MVP]

                  #9
                  Re: Debugging thread problem


                  "John Brown" <no_spam@_nospa m.comwrote in message
                  news:uasjqmG2GH A.4176@TK2MSFTN GP06.phx.gbl...
                  | >What kind of application is this? Windows forms or console like.
                  | >If Windows forms, do you pass the form object to the other thread?
                  | >
                  | Well, the worker thread's main function (entry point) is a member of a
                  | "Form" derivative and it passes a reference to the enclosing object
                  (form)
                  | to a function in another file and that's exactly where things start
                  | failing (as soon as the latter function is called). However, note that
                  all
                  | GUI processing is being routed back to the main GUI thread via
                  | "Control.Invoke ()". In any case, is there a reason it should fail as
                  soon
                  | that function is called (perhaps you're alluding to some marshalling
                  issue
                  | I haven't considered - does the form's reference need to be marshalled
                  to
                  | the thread in some way). Thanks for your assistance (appreciated).
                  |
                  | By sheer coincidence I came across the following link while pursuing
                  another
                  | matter related to this problem (what luck!). I'm still tinkering but the
                  | "DebuggerDispla y" attribute seems to have solved the problem for the
                  moment.
                  | See the "System.Windows .Forms.Form and multithreading" section here:
                  |
                  | http://blogs.msdn.com/greggm/archive...18/494648.aspx
                  |
                  |

                  Righht John, that's exactly what you are after, I hope one of the
                  work-arounds will help you out.

                  Willy.


                  Comment

                  • John Brown

                    #10
                    Re: Debugging thread problem

                    Righht John, that's exactly what you are after, I hope one of the
                    work-arounds will help you out.
                    So far so good. Thanks for your help. Hopefully MSFT will get around to
                    repairing this situation as I'm sure many others have endured the same
                    frustration.


                    Comment

                    Working...