diff options
author | sr55 <[email protected]> | 2012-02-14 20:07:18 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-02-14 20:07:18 +0000 |
commit | 4da15bcbbbd800b7af230294224f0d7248e8dd72 (patch) | |
tree | 8ae8dc54e7be4f1bb63a49af5b29f22b4da969e2 /win/CS/HandBrake.ApplicationServices/Functions | |
parent | e249cb1d709572cc7ef8013a298d808221b1cc25 (diff) |
WinGui: Fix AllowSleep/Prevent Sleep to always use the same thread. Fix an exception when using up arrows on the tile dropdown before performing a scan.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4448 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Functions')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Functions/Win32.cs | 62 |
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;
}
}
}
|