The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Q & A: My VB6 App Doesn’t Refresh in Session 0 — Help!

  We have a VB6 application we’re running as a service in AlwaysUp on Windows Server 2012 R2. When we run the application outside of AlwaysUp, the form refreshes fine. When we run the application in AlwaysUp, it can sometimes take several minutes for the form to refresh, starting out as a black form (see screenshot of Session 0 below). Any recommendations you might have to help with the refresh rate would be appreciated, thanks.

Application not refreshing in Session 0

— Jim Kinghorn, Taylor Technology Services

Hi Jim. You are running into one of the peculiarities of Session 0 — where user interface elements do not seem to be refreshed consistently. Unfortunately it is a “Windows thing” and is outside the control of AlwaysUp.

But all is not lost! Our development team took a look at your situation and concluded that calling the Windows RedrawWindow API function in Session 0 might fix the problem.

You have a couple of options:

Option #1: Update your code to refresh all windows periodically

Specifically, your code should:

  • Refresh the desktop window, by calling the VB6 equivalent of:

    RedrawWindow(NULL, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN)

  • Enumerate all top-level windows (using the EnumWindows API function) and call RedrawWindows on each visible window.

Performing those operations every few seconds should eliminate the black windows in Session 0.

Option #2: Setup our “RefreshWindows” utility to run in Session 0

If updating the code is not a viable option, you can:

  • Download our free RefreshWindows command line utility and save it to a folder of your choice. When run, the utility refreshes all windows every 5 seconds (using the RedrawWindows and EnumWindows functions as recommended above):

    Running RefreshWindows
  • Set it up as a Windows Service with AlwaysUp. All you should have to provide is the full path to the executable file on the “General” tab:

    Setup RefreshWindows as a Windows Service with AlwaysUp

When your machine boots, AlwaysUp will launch RefreshWindows.exe to ensure that all windows in Session 0 are periodically refreshed and properly drawn.

Enjoy!

Posted in AlwaysUp | Tagged , , , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *