GUI does not redraw while stepping in Debug Mode

后端 未结 3 386
心在旅途
心在旅途 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).

    0 讨论(0)
  • 2021-01-21 17:22

    The reason for this is because you can only have one UI thread, and when you enter your method that updates that code that code begins blocking the UI thread. It will not update until your method exits.

    Here is a good SO on message pumps, which are what drive the UI updates

    You should be able to use Add Watch/Quick Watch to look at any values at the time of debugging. This sounds like what you are really looking for, anyway.

    0 讨论(0)
  • 2021-01-21 17:41

    Like everyone else has said in answers and comments, the UI thread is blocked so it cannot be redrawn.

    However, if all you want to do is see the GUI, and not interact with it, and you are running Windows 7/8 (which sounds unlikely since you're using VS2005) and haven't disabled aero peek, you can mouse over your application in the task bar and Windows will show the preview thumbnail. When you mouse over the thumbnail, you can "peek" at the application even when the breakpoint is blocking the UI thread.

    0 讨论(0)
提交回复
热议问题