Skip to content

Commit

Permalink
CA1060: Move P/Invokes to NativeMethods class
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasNilson committed Oct 5, 2022
1 parent e36da30 commit c7fcd60
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Source/IdleMasterExtended/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ namespace IdleMasterExtended
{
public partial class frmMain : Form
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern ExecutionState SetThreadExecutionState(ExecutionState esFlags);
[FlagsAttribute]
private enum ExecutionState : uint
{
EsAwaymodeRequired = 0x00000040,
EsContinuous = 0x80000000,
EsDisplayRequired = 0x00000002,
EsSystemRequired = 0x00000001
}

private Statistics statistics = new Statistics();
public List<Badge> AllBadges { get; set; }

Expand Down Expand Up @@ -648,8 +637,8 @@ private void RefreshGamesStateListView()
#endregion

#region MISC
private static void PreventSleep() => SetThreadExecutionState(ExecutionState.EsContinuous | ExecutionState.EsSystemRequired);
private static void AllowSleep() => SetThreadExecutionState(ExecutionState.EsContinuous);
private static void PreventSleep() => NativeMethods.SetThreadExecutionState(NativeMethods.ExecutionState.EsContinuous | NativeMethods.ExecutionState.EsSystemRequired);
private static void AllowSleep() => NativeMethods.SetThreadExecutionState(NativeMethods.ExecutionState.EsContinuous);

private static void CreateShutdownProcess(String parameters)
{
Expand Down Expand Up @@ -1492,4 +1481,18 @@ private void ApplyIcons()
}
#endregion
}
}

internal static class NativeMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern ExecutionState SetThreadExecutionState(ExecutionState esFlags);
[FlagsAttribute]
internal enum ExecutionState : uint
{
EsAwaymodeRequired = 0x00000040,
EsContinuous = 0x80000000,
EsDisplayRequired = 0x00000002,
EsSystemRequired = 0x00000001
}
}

0 comments on commit c7fcd60

Please sign in to comment.