Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to turn the Windows ghosting feature back on after DisableProcessWindowsGhosting?

Tags:

windows

winapi

We have an application that do heavy work in the main thread. To prevent Windows from deeming it 'Not Responding' and starting the ghosting feature (as described in section 'Hangs - Operating System Perspective' in this link) during the heavy work, we could use DisableProcessWindowsGhosting to turn the ghosting feature off.

But we don't want to turn it off for the rest of the session, we want to turn it back on once the heavy work is done. Unfortunately Windows doesn't provide any (documented) API for that.

Is there any (possibly hacky) way to turn it back on?

As an interesting note, when the application runs in VC debugger, the ghosting feature is turned off, but once the it's detached, it's back on. There must be something the debugger does, any idea?

like image 277
techolic Avatar asked Sep 28 '12 03:09

techolic


1 Answers

Disregarding the fact, that doing heavy work on the UI thread is wrong in itself (heavy work should be done on a separate thread that optionally communicates its progress to the UI), the suggestions below are only for the sake of answering the question, to support the legacy code scenario mentioned in the comments.

DisableProcessWindowsGhosting is a one-way road and disables the ghosting feature for the life-time of the process, so the only re-enabling condition is to restart the process as whole.

Otherwise all applications that are being debugged (not just in VC debugger, but any debugger), are also exempted from ghosting. If you wanted to hack this condition, you could make a companion application, that will attach to your application as debugger (DebugActiveProcess) during the heavy work, and detach itself (DebugSetProcessKillOnExit(FALSE)+DebugActiveProcessStop) after it's done. This will degrade performance and can cause problems with elevation, forking and SEH to name a few.

Minimized windows are supposed to be exempted from ghosting as well, but I haven't tested this one myself.

like image 141
Ai4rei Avatar answered Nov 13 '22 13:11

Ai4rei