Results 1 to 6 of 6

Thread: Code Stepping Fails

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Code Stepping Fails

    If anybody wants to see the lengthy back story, it is in this thread:

    https://www.vbforums.com/showthread....48#post5585048

    In that thread, I was able to find and fix the bug that was ultimately causing the problem, but it wasn't a very satisfying solution, because I felt that there was a second bug that had just been hidden by fixing the first bug.

    I got back to studying that today, and found something that amazes me. I'd like to see if anybody has any comments on it.

    I have a class that raises an event. This event may or may not be handled by...well, whoever wants to, really. In fact, I have several events like that, so I have a fair amount of experience with that.

    Normally, when you raise an event in debug mode, you can step through all the event handlers (so long as they are accessible) by pressing F11 repeatedly. This morning, I was testing exactly that to see who handled an earlier event in the sequence that leads to the event in question. However, when I got to the event in question and pressed F11, I moved right on to the next line. Now, I KNEW that wasn't right, because I knew of some code that handled the event, and I knew that code was reachable. Therefore, I set a breakpoint in the code that I knew handled the event, and raised the event again. This time, with the breakpoint in place, I was able to step through the method correctly. I then removed the breakpoint, and raised the event again. Once again, I didn't step into the code I had JUST stepped through.

    One thing to note is that I wasn't restarting the program during this. I stepped through the event raising without stepping into any handlers, then set the breakpoint, dragged the execution point back to the RaiseEvent statement, stepped forwards...and right into the event handler, and once out of the event handler, I removed the breakpoint from the event handler, dragged the execution point back to the RaiseEvent statement, and stepped forwards...right over the event handler without going into it.

    So, for this particular custom event, I don't automatically step into event handlers. Instead, I step right over them unless they have a breakpoint in them, in which case I step into them. For some custom events that were raised just before this one, I automatically step into event handlers regardless of whether or not there is a breakpoint in them. The only difference that exists between the two events is that the one I don't automatically step into is an event of the class that calls RaiseEvent, while the event that I do automatically step into is an event of a different class. That event gets raised by a method call from the first class. I don't believe that's significant, because whether or not I am able to automatically step into event handlers, I always step to the RaiseEvent method first, regardless of which class it is in.

    Has anybody seen this before? Can anybody say why I sometimes can step into event handlers and sometimes I can't?
    My usual boring signature: Nothing

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Code Stepping Fails

    I've had this happen before on asynchronous methods firing events. What happens is that my breakpoint is on thread B and the event is firing on thread A and so hitting F11 doesn't go from B to A.

    If that is the case in this situation, there is a thread dropdown at the top of Visual Studio (just under the start debugging icon), try changing it before hitting F11.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Code Stepping Fails

    This is entirely synchronous, but there may be something to that. After all, there is one difference between this event and the other events that I've stepped through: There's an open DB transaction when this event is raised. That may be enough to confuse VS in some way.
    My usual boring signature: Nothing

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Code Stepping Fails

    Are you using some form of ORM to handle the database operations for you?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Code Stepping Fails

    Nope. It's all raw SQL.
    My usual boring signature: Nothing

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Code Stepping Fails

    Man, that’s really odd. I wouldn’t expect that sort of behavior, then again Im not sure I’m in a position to know for sure.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width