Search code examples
vb.netmultithreadingwinformsvisual-studio-debuggingalt-tab

Running winforms app from debugger disables alt-tab switching to form


I have a Winforms app with a main form where a multiline text box is updated during a long running process.

I would like to be able to use the ALT-TAB facility of Windows to switch away from the Visual Studio 2012 IDE to watch the form being updated as the app runs.

Is there some option that controls this? If I have other apps running such as Notepad I can toggle away from the IDE but navigating in this way to the running Winforms app seems to be disabled.

Last time I debugged an app like this I recall this sort of switching worked but sometimes there was a lag in the rendering of the screen.

The winforms app is not multithreaded.

Any ideas?


Solution

  • The winforms app is not multithreaded.

    Which means you're doing all your lengthy processing on the UI thread. And that, in turn, means that during that processing, your app is ignoring all the messages Windows is sending it, like the "hey, somebody just Alt+Tabbed to you, so bring yourself to the front" message.

    You either need to sprinkle your code with frequent calls to Application.DoEvents (not recommended, but could work if you don't intend to maintain this app long-term), or move your long-running logic into a background thread so your UI thread can stay responsive to messages.