Keep windows screen active using C#

In some certain scenarios, we require to keep our screen active to restrict windows to launching screen saver or not allowing to go windows in idle mode.

Here’s C# code snip which’ll keep screen active.
using System.Runtime.InteropServices;
namespace DisableIdleMode
{
class Program
{
static void Main(string[] args)
{
KeepScreenActive();
Console.Read();
}

///Method
public static void KeepScreenActive()
{
SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
}

[DllImport(“kernel32.dll”)]
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
[FlagsAttribute]
enum EXECUTION_STATE : uint
{
ES_AWAYMODE_REQUIRED = 0x00000040,
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
}
}
}

--

--

No responses yet