Saturday, April 30, 2011

AX 2009 client freezes and doesn't redraw its window during long operations (FIX!)

Hey, it's been a long time since the last post!.. Anyway, when you run a long lasting operation in AX 2009, after about 5 seconds a client window would blink - and bam! it's in the Not Responding state and doesn't redraw anything. This behavior has been annoying me since I've first seen AX 2009 but now there seems to be a solution! I've found it accidentally in this post of the EMEA Dynamics AX Support blog. Here what they say:

...One reason for running into this issue can be if the Windows Operating System is replacing the Dynamics AX application window by a ghost window. When Dynamics AX starts a lengthy COM operation, it is not responding to messages sent by the Windows Operating System in time. So Windows supposes Dynamics AX has stopped responding. When this happens the Dynamics AX application window is replaced by a ghost window until Dynamics AX resumes. Window ghosting is a nice feature that allows the user to minimize, move or close the main window even if the application is not responding. You can easily identify a ghost window as it shows (Not responding) in the window title.

One of the proposed solutions is to run a client in the WinXP SP2 compatibility mode, but it requires you to create a special shortcut for it and run every deployed client with such a shortcut, which is not always convenient. But theres's also another way.

The Win32 API function DisableProcessWindowsGhosting can disable windows ghosting feature for the calling process and you can customize your Dynamics AX application to make the client call this function on startup. All you have to do is add a new method to the WinAPI class:

/// <summary>
/// Call user32.DisableProcessWindowsGhosting
/// </summary>
/// <remarks>
/// Disables the window ghosting feature for the calling GUI process. Window
/// ghosting is a Windows Manager feature that lets the user minimize, move,
/// or close the main window of an application that is not responding.
/// </remarks>
public static client void disableProcessWindowsGhosting()
{
    DLL         dll     = new DLL(#UserDLL);
    DLLFunction dllFunc = new DLLFunction(dll, @"DisableProcessWindowsGhosting");
    ;
    dllFunc.returns(ExtTypes::void);
    dllFunc.arg();

    dllFunc.call();
}

And then call it say from info.startupPost():

/*
No SYS code must exist in this method
*/
void startupPost()
{
    if (clientKind() == ClientType::Client)
    {
        // BP deviation documented
        WinAPI::disableProcessWindowsGhosting();
    }
}

This Win32 API function is supported in at least WinXP SP3 and Windows Server 2003 SP2. It's a pity windows ghosting is not disabled by the client kernel itself.

3 comments:

Joe Robinson said...

Are there any adverse side effects of this fix?

Joe Robinson said...

Are there any adverse side effects to disabling window ghosting?

gl00mie said...

I'm personally not aware of any; this fix has been being used for a couple of years in several AX installations with over 1000 total concurrent clients.