On Windows, each thread has an execution state which can be set by calling SetThreadExecutionState
. For example, if a thread calls:
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED)
then Windows will not turn off the display, until that thread changes its execution state, or terminates.
It can be accessed from C#:
[DllImport("kernel32.dll", SetLastError = true)] SetThreadExecutionState(...)
But, while SetThreadExecutionState
sets the execution state, there doesn't appear to be any equivalent GetThreadExecutionState
API. kernel32.dll
exports SetThreadExecutionState
but not GetThreadExecutionState
. I tried:
[DllImport("kernel32.dll", SetLastError = true)] internal static extern uint GetThreadExecutionState();
But I got a System.EntryPointNotFoundException
saying GetThreadExecutionState
does not exist in kernel32.dll
.
How then can I find out the execution state of the current thread without changing it?