2

The application runs longer on computer but if computer goes to sleep mode, there will be problem. Is there any way to prevent from sleep mode ?

0

1 Answer 1

4

Define a class like this:

internal static class NativeMethods { // Import SetThreadExecutionState Win32 API and necessary flags [DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags); public const uint ES_CONTINUOUS = 0x80000000; public const uint ES_SYSTEM_REQUIRED = 0x00000001; } 

Put this to the main method: (make sure its before application.run call)

// Set new state to prevent system sleep. (Note: still allows screen saver) var previousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED); 
Sign up to request clarification or add additional context in comments.

1 Comment

Lone link is considered a poor answer since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.