namespace HandBrake.ApplicationServices.Services\r
{\r
using System;\r
+ using System.ComponentModel;\r
using System.Diagnostics;\r
using System.IO;\r
using System.Text;\r
using HandBrake.ApplicationServices.Model;\r
using HandBrake.ApplicationServices.Parsing;\r
using HandBrake.ApplicationServices.Services.Interfaces;\r
+ using HandBrake.ApplicationServices.Utilities;\r
\r
/// <summary>\r
/// Class which handles the CLI\r
/// </summary>\r
private Win7 windowsSeven = new Win7();\r
\r
+ /// <summary>\r
+ /// A Lock for the filewriter\r
+ /// </summary>\r
+ static readonly object fileWriterLock = new object();\r
+\r
#endregion\r
\r
/// <summary>\r
CreateNoWindow = !Init.ShowCliForInGuiEncodeStatus ? true : false\r
};\r
\r
- this.HbProcess = Process.Start(cliStart);\r
+ this.HbProcess = new Process { StartInfo = cliStart };\r
+\r
+ this.HbProcess.Start();\r
\r
if (enableLogging)\r
{\r
private void HbProcessExited(object sender, EventArgs e)\r
{\r
IsEncoding = false;\r
- \r
if (windowsSeven.IsWindowsSeven)\r
{\r
windowsSeven.SetTaskBarProgressToNoProgress();\r
\r
try\r
{\r
- if (fileWriter != null)\r
+ lock (fileWriterLock)\r
{\r
- fileWriter.Close();\r
- fileWriter.Dispose();\r
+ // This is just a quick hack to ensure that we are done processing the logging data.\r
+ // Logging data comes in after the exit event has processed sometimes. We should really impliment ISyncronizingInvoke\r
+ // and set the SyncObject on the process. I think this may resolve this properly.\r
+ // For now, just wait 2.5 seconds to let any trailing log messages come in and be processed.\r
+ Thread.Sleep(2500);\r
+\r
+ this.HbProcess.CancelErrorRead();\r
+\r
+ if (fileWriter != null)\r
+ {\r
+ fileWriter.Close();\r
+ fileWriter.Dispose();\r
+ }\r
+\r
+ fileWriter = null;\r
}\r
}\r
catch (Exception exc)\r
lock (logBuffer)\r
logBuffer.AppendLine(e.Data);\r
\r
- if (fileWriter != null && fileWriter.BaseStream.CanWrite)\r
+ lock (fileWriterLock)\r
{\r
- fileWriter.WriteLine(e.Data);\r
-\r
- // If the logging grows past 100MB, kill the encode and stop.\r
- if (fileWriter.BaseStream.Length > 100000000)\r
+ if (fileWriter != null && fileWriter.BaseStream.CanWrite)\r
{\r
- this.Stop(new Exception("The encode has been stopped. The log file has grown to over 100MB which indicates a serious problem has occured with the encode." +\r
- "Please check the encode log for an indication of what the problem is."));\r
+ fileWriter.WriteLine(e.Data);\r
+\r
+ // If the logging grows past 100MB, kill the encode and stop.\r
+ if (fileWriter.BaseStream.Length > 100000000)\r
+ {\r
+ this.Stop(\r
+ new Exception(\r
+ "The encode has been stopped. The log file has grown to over 100MB which indicates a serious problem has occured with the encode." +\r
+ "Please check the encode log for an indication of what the problem is."));\r
+ }\r
}\r
}\r
}\r
catch (Exception exc)\r
{\r
- // errorService.ShowError("Unable to write log data...", exc.ToString());\r
+ // Do Nothing.\r
}\r
}\r
}\r