From 56bf9b80b9b55ecaec9855addda41898261d26b1 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 2 Sep 2012 15:12:06 +0000 Subject: WinGui: Further work and fixes on the Process Isolation Service git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4929 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/Encode.cs | 7 ++++++ .../Services/ServerService.cs | 27 ++++++++++++++-------- .../Utilities/Win32.cs | 3 +-- 3 files changed, 26 insertions(+), 11 deletions(-) (limited to 'win/CS/HandBrake.ApplicationServices') diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs index dbf598796..fa21353ed 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs @@ -373,6 +373,13 @@ namespace HandBrake.ApplicationServices.Services /// Time Left private void EncodeOnEncodeProgress(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float avg, string timeRemaining) { + if (!this.IsEncoding) + { + // We can get events out of order since the CLI progress is monitored on a background thread. + // So make sure we don't send a status update after an encode complete event. + return; + } + EncodeProgressEventArgs eventArgs = new EncodeProgressEventArgs { AverageFrameRate = avg, diff --git a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs index 277a7c5b3..f6b6edf44 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/ServerService.cs @@ -13,6 +13,7 @@ namespace HandBrake.ApplicationServices.Services using System.Collections.Generic; using System.Runtime.Serialization; using System.ServiceModel; + using System.Threading; using System.Windows; using HandBrake.ApplicationServices.EventArgs; @@ -47,7 +48,12 @@ namespace HandBrake.ApplicationServices.Services /// /// The host. /// - private ServiceHost host; + private static ServiceHost host; + + /// + /// The shutdown flag. + /// + private static ManualResetEvent shutdownFlag; #endregion @@ -148,18 +154,20 @@ namespace HandBrake.ApplicationServices.Services /// public void Start(string port) { - using (this.host = new ServiceHost(typeof(ServerService), new Uri(string.Format("net.tcp://127.0.0.1:{0}", port)))) + using (host = new ServiceHost(typeof(ServerService), new Uri(string.Format("net.tcp://127.0.0.1:{0}", port)))) { // Setup a listener - this.host.AddServiceEndpoint(typeof(IServerService), new NetTcpBinding(), "IHbService"); - this.host.Open(); - Console.WriteLine("::: HandBrake Isolation Server:::"); + host.AddServiceEndpoint(typeof(IServerService), new NetTcpBinding(), "IHbService"); + host.Open(); + Console.WriteLine("::: HandBrake Isolation Server - Debug Console:::"); Console.WriteLine("Service Started. Waiting for Clients..."); // Setup the services we are going to use. scanService = new ScanService(new UserSettingService()); // TODO this needs wired up with castle encodeService = new Encode(new UserSettingService()); - Console.ReadLine(); + + shutdownFlag = new ManualResetEvent(false); + shutdownFlag.WaitOne(); } } @@ -186,10 +194,11 @@ namespace HandBrake.ApplicationServices.Services /// public void Stop() { - if (this.host != null) + if (host != null) { - this.host.Close(); - Application.Current.Shutdown(); + host.BeginClose(null, null); + //host.Abort(); + shutdownFlag.Set(); } } diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Win32.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Win32.cs index 892c4bcad..acc8948a1 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/Win32.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/Win32.cs @@ -168,8 +168,7 @@ namespace HandBrake.ApplicationServices.Utilities /// public static void AllowSleep() { - executor( - () => SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS)); + SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS); } /// -- cgit v1.2.3