OSDN Git Service

WinGui:
authorsr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 17 Sep 2010 18:28:54 +0000 (18:28 +0000)
committersr55 <sr55@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 17 Sep 2010 18:28:54 +0000 (18:28 +0000)
- Another fix to the Encode Log Writer which should hopefully fix the "ObjectDisposedException" some users were seeing.

git-svn-id: svn://localhost/HandBrake/trunk@3538 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/C#/HandBrake.ApplicationServices/Services/Encode.cs
win/C#/HandBrake.ApplicationServices/Services/ErrorService.cs

index d922b66..42d2822 100644 (file)
@@ -346,7 +346,10 @@ namespace HandBrake.ApplicationServices.Services
             try\r
             {\r
                 if (fileWriter != null)\r
+                {\r
                     fileWriter.Close();\r
+                    fileWriter.Dispose();\r
+                }\r
             }\r
             catch (Exception exc)\r
             {\r
@@ -430,7 +433,10 @@ namespace HandBrake.ApplicationServices.Services
             catch (Exception exc)\r
             {\r
                 if (fileWriter != null)\r
+                {\r
                     fileWriter.Close();\r
+                    fileWriter.Dispose();\r
+                }\r
 \r
                 errorService.ShowError("Error", exc.ToString());\r
             }\r
@@ -454,12 +460,14 @@ namespace HandBrake.ApplicationServices.Services
 \r
                 try\r
                 {\r
-                    if (fileWriter != null)\r
+                    if (fileWriter != null && fileWriter.BaseStream.CanWrite)\r
+                    {\r
                         fileWriter.WriteLine(e.Data);\r
+                    }            \r
                 }\r
                 catch (Exception exc)\r
                 {\r
-                   // errorService.ShowError("Unable to write log data...", exc.ToString());\r
+                    // errorService.ShowError("Unable to write log data...", exc.ToString());\r
                 }\r
             }\r
         }\r
index a45cd11..7b75ce8 100644 (file)
@@ -28,8 +28,15 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         public void ShowError(string shortError, string longError)\r
         {\r
-            Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));\r
-            newThread.Start(shortError + Environment.NewLine + longError);\r
+            try\r
+            {\r
+                Thread newThread = new Thread(new ParameterizedThreadStart(WriteExceptionToFile));\r
+                newThread.Start(shortError + Environment.NewLine + longError);\r
+            }\r
+            catch (Exception)\r
+            {\r
+                // Do Nothing\r
+            }\r
 \r
             ExceptionWindow window = new ExceptionWindow();\r
             window.Setup(shortError, longError);\r
@@ -37,6 +44,20 @@ namespace HandBrake.ApplicationServices.Services
         }\r
 \r
         /// <summary>\r
+        /// Show a Notice or Warning Message.\r
+        /// </summary>\r
+        /// <param name="notice">\r
+        /// The text to display to the user\r
+        /// </param>\r
+        /// <param name="isWarning">\r
+        /// Is a warning window, show the warning icon instead of the notice\r
+        /// </param>\r
+        public void ShowNotice(string notice, bool isWarning)\r
+        {\r
+            throw new NotImplementedException();\r
+        }\r
+\r
+        /// <summary>\r
         /// Write Exceptions out to log files\r
         /// </summary>\r
         /// <param name="state">\r
@@ -44,11 +65,11 @@ namespace HandBrake.ApplicationServices.Services
         /// </param>\r
         public void WriteExceptionToFile(object state)\r
         {\r
-            string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
-            string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));\r
-\r
             try\r
             {\r
+                string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+                string file = Path.Combine(logDir, string.Format("Exception_{0}.txt", DateTime.Now.Ticks));\r
+\r
                 if (!File.Exists(file))\r
                 {\r
                     using (StreamWriter streamWriter = new StreamWriter(file))\r
@@ -64,19 +85,5 @@ namespace HandBrake.ApplicationServices.Services
                 return; // Game over. Stop digging.\r
             }\r
         }\r
-\r
-        /// <summary>\r
-        /// Show a Notice or Warning Message.\r
-        /// </summary>\r
-        /// <param name="notice">\r
-        /// The text to display to the user\r
-        /// </param>\r
-        /// <param name="isWarning">\r
-        /// Is a warning window, show the warning icon instead of the notice\r
-        /// </param>\r
-        public void ShowNotice(string notice, bool isWarning)\r
-        {\r
-            throw new NotImplementedException();\r
-        }\r
     }\r
 }\r