How to prevent Windows from entering idle state?

后端 未结 5 1108
执念已碎
执念已碎 2020-11-27 14:38

I am working on a C# application which runs in the background without any Windows control.

I want to notify Windows that my application is still alive to prevent Win

5条回答
  •  Happy的楠姐
    2020-11-27 15:21

    You can use SetThreadExecutionState described here:

    • SetThreadExecutionState Function

    Since it is a Win32 API function, to use it from C# you'll need to PInvoke it. The steps are described here, including a sample method PreventSleep to temporarily disable sleep mode:

    • PInvoke.net: setthreadexecutionstate (kernel32)

提交回复
热议问题