Debugger help. Interrupting an endless loop?

Mugsy's RapSheet 196 Reputation points
2022-03-09T14:02:47.237+00:00

My program appears to be stuck in an endless loop, but I have no idea where.

Clicking the pause button during testing in real-time simply gives me "System.Windows.Forms.NotLoaded" error unrelated to my program and doesn't show me where it is stuck.

Is there a way to stop my program in mid-execution so I can see exactly where it is stuck?

TIA

Developer technologies Visual Studio Debugging
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-03-09T15:56:44.763+00:00

    Yes they are called breakpoints. In your code in the loop that is infinite select one of the lines with the mouse and press F9 (default). Alternatively go to the grey margin on the left in the editor and click. In either case you'll see the red stop sign indicating a breakpoint is set. Now run your code. Every time the debugger hits that line it'll pause the program and throw you into the code.

    Now you can step through your code using F10/F11 to verify each line is executing the way you want. Refer to this article on how to use breakpoints and step through code.

    As for your actual problem you need to ensure that the loop variant (the thing that keeps the loop condition true) eventually becomes false in your code. If it doesn't and you have no break/return statements in your loop then it is infinite.

    0 comments No comments

  2. Mugsy's RapSheet 196 Reputation points
    2022-03-09T17:29:50.427+00:00

    Thx for the reply, but I'm aware of breakpoints.

    The problem is I don't/didn't know where the "loop" is/was taking place to know were to place a breakpoint.

    No matter now. I managed to figure out that the problem was not inside a loop at all. It was getting stuck on a trapped error and the alert was buried under the form. (ugh)

    Thx.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.