summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Functions/Win32.cs62
1 files changed, 58 insertions, 4 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs b/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs
index 8cb464b80..94a34f529 100644
--- a/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs
+++ b/win/CS/HandBrake.ApplicationServices/Functions/Win32.cs
@@ -6,7 +6,11 @@
namespace HandBrake.ApplicationServices.Functions
{
using System;
+ using System.ComponentModel;
+ using System.Diagnostics;
using System.Runtime.InteropServices;
+ using System.Windows;
+ using System.Windows.Threading;
/// <summary>
/// Win32 API calls
@@ -14,6 +18,11 @@ namespace HandBrake.ApplicationServices.Functions
public class Win32
{
/// <summary>
+ /// Used to force UI Thread.
+ /// </summary>
+ private static Action<Action> executor = action => action();
+
+ /// <summary>
/// Set the Forground Window
/// </summary>
/// <param name="hWnd">
@@ -52,13 +61,21 @@ namespace HandBrake.ApplicationServices.Functions
public struct MEMORYSTATUSEX
{
public int dwLength;
+
public int dwMemoryLoad;
+
public ulong ullTotalPhys;
+
public ulong ullAvailPhys;
+
public ulong ullTotalPageFile;
+
public ulong ullAvailPageFile;
+
public ulong ullTotalVirtual;
+
public ulong ullAvailVirtual;
+
public ulong ullAvailExtendedVirtual;
}
@@ -74,7 +91,6 @@ namespace HandBrake.ApplicationServices.Functions
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
-
/// <summary>
/// Generate a Console Ctrl Event
/// </summary>
@@ -112,7 +128,7 @@ namespace HandBrake.ApplicationServices.Functions
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
+ private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
/// <summary>
/// Execution State
@@ -121,16 +137,29 @@ namespace HandBrake.ApplicationServices.Functions
public enum EXECUTION_STATE : uint
{
ES_SYSTEM_REQUIRED = 0x00000001,
+
ES_CONTINUOUS = 0x80000000,
+
ES_AWAYMODE_REQUIRED = 0x00000040
}
/// <summary>
+ /// Initializes static members of the <see cref="Win32"/> class.
+ /// </summary>
+ static Win32()
+ {
+ InitializeWithDispatcher();
+ }
+
+ /// <summary>
/// Prevent the system from sleeping
/// </summary>
public static void PreventSleep()
{
- SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);
+ executor(
+ () => SetThreadExecutionState(
+ EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED
+ | EXECUTION_STATE.ES_AWAYMODE_REQUIRED));
}
/// <summary>
@@ -138,7 +167,32 @@ namespace HandBrake.ApplicationServices.Functions
/// </summary>
public static void AllowSleep()
{
- SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
+ executor(
+ () => SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS));
+ }
+
+ /// <summary>
+ /// Initializes the framework using the current dispatcher.
+ /// </summary>
+ public static void InitializeWithDispatcher()
+ {
+ var dispatcher = Dispatcher.CurrentDispatcher;
+
+ SetUIThreadMarshaller(action =>
+ {
+ if (dispatcher.CheckAccess())
+ action();
+ else dispatcher.Invoke(action);
+ });
+ }
+
+ /// <summary>
+ /// Sets a custom UI thread marshaller.
+ /// </summary>
+ /// <param name="marshaller">The marshaller.</param>
+ public static void SetUIThreadMarshaller(Action<Action> marshaller)
+ {
+ executor = marshaller;
}
}
}