GUI does not redraw while stepping in Debug Mode

后端 未结 3 385
心在旅途
心在旅途 2021-01-21 16:37

In any .NET 2.0 Winforms application, if you run the code in Debug Mode, and you either hit a breakpoint or otherwise Step Into the code line by line, and you want to see the GU

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 17:17

    What is the reason for this

    While you're debugging, you're effectively blocking the UI thread - you're manually stepping through its execution flow. The UI thread can't draw the UI while you're stopping it from executing.

    and is there a way to overcome this

    You could try calling Application.DoEvents() manually, but I'd generally recommend against it.

    It would be better to just wait until you got to the end of the method and let the UI redraw itself normally. If your method is very long (in terms of time) then bear in mind that when not debugging, the UI still wouldn't be able to update itself while that method is executing. This may cause you to change your design (it's hard to tell just from the information we've got at the moment).

提交回复
热议问题