diff options
author | sr55 <[email protected]> | 2012-09-02 15:12:06 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-09-02 15:12:06 +0000 |
commit | 56bf9b80b9b55ecaec9855addda41898261d26b1 (patch) | |
tree | c2cf34ebd4d7e8695c2764a0a813ad11a7f035a8 /win/CS | |
parent | bf7e3f6e6ef524ef8245b57f5e11b3e101525c99 (diff) |
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
Diffstat (limited to 'win/CS')
7 files changed, 52 insertions, 22 deletions
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 /// <param name="timeRemaining">Time Left</param>
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 /// <summary>
/// The host.
/// </summary>
- private ServiceHost host;
+ private static ServiceHost host;
+
+ /// <summary>
+ /// The shutdown flag.
+ /// </summary>
+ private static ManualResetEvent shutdownFlag;
#endregion
@@ -148,18 +154,20 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
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 /// </summary>
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 /// </summary>
public static void AllowSleep()
{
- executor(
- () => SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS));
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
/// <summary>
diff --git a/win/CS/HandBrake.Server/Program.cs b/win/CS/HandBrake.Server/Program.cs index 3ec5e2248..b6fc92736 100644 --- a/win/CS/HandBrake.Server/Program.cs +++ b/win/CS/HandBrake.Server/Program.cs @@ -21,8 +21,11 @@ {
if (args.Count() != 1)
{
- Console.WriteLine("Invalid Arguments");
- Console.ReadLine();
+ //Console.WriteLine("Invalid Arguments");
+ //Console.ReadLine();
+
+ IServerService server = new ServerService();
+ server.Start("8001");
}
else
{
diff --git a/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs b/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs index db175b45a..13bf132ee 100644 --- a/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs +++ b/win/CS/HandBrakeWPF/Isolation/BackgroundServiceConnector.cs @@ -108,13 +108,18 @@ namespace HandBrakeWPF.Isolation "HandBrake.Server.exe", port)
{
UseShellExecute = false,
- CreateNoWindow = false,
+ CreateNoWindow = true,
+ RedirectStandardOutput = true,
};
backgroundProcess = new Process { StartInfo = processStartInfo };
backgroundProcess.Start();
}
+ // When the process writes out a line, it's pipe server is ready and can be contacted for
+ // work. Reading line blocks until this happens.
+ backgroundProcess.StandardOutput.ReadLine();
+
ThreadPool.QueueUserWorkItem(delegate
{
try
@@ -141,16 +146,16 @@ namespace HandBrakeWPF.Isolation /// </summary>
public void Disconnect()
{
- if (backgroundProcess != null && !backgroundProcess.HasExited)
+ try
{
- try
+ if (backgroundProcess != null && !backgroundProcess.HasExited)
{
Service.Unsubscribe();
}
- catch (Exception exc)
- {
- this.errorService.ShowError("Unable to disconnect from service", "It may have already close. Check for any left over HandBrake.Server.exe processes", exc);
- }
+ }
+ catch (Exception exc)
+ {
+ this.errorService.ShowError("Unable to disconnect from service", "It may have already close. Check for any left over HandBrake.Server.exe processes", exc);
}
}
diff --git a/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs b/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs index 504024b43..322d30f9f 100644 --- a/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs +++ b/win/CS/HandBrakeWPF/Isolation/IsolatedEncodeService.cs @@ -84,7 +84,7 @@ namespace HandBrakeWPF.Isolation {
get
{
- return Service.EncodeActivityLog;
+ return this.IsConnected ? this.Service.EncodeActivityLog : "Unable to connect to background worker service ...";
}
}
@@ -95,7 +95,7 @@ namespace HandBrakeWPF.Isolation {
get
{
- return Service.IsEncoding;
+ return this.IsConnected && this.Service.IsEncoding;
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index a22fa83d9..3e8b5709f 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -827,6 +827,13 @@ namespace HandBrakeWPF.ViewModels isolatedScanService.Disconnect();
}
+ IIsolatedEncodeService isolatedEncodeService = this.encodeService as IIsolatedEncodeService;
+ if (isolatedEncodeService != null)
+ {
+ // Kill any background services for this instance of HandBrake.
+ isolatedEncodeService.Disconnect();
+ }
+
// Unsubscribe from Events.
this.scanService.ScanStared -= this.ScanStared;
this.scanService.ScanCompleted -= this.ScanCompleted;
|