InitializeComponent();\r
this.rtf_actLog.Text = string.Empty;\r
\r
+ // When the window closes, we want to abort the monitor thread.\r
+ this.Disposed += new EventHandler(forceQuit);\r
+\r
mainWindow = fm;\r
queueWindow = fq;\r
read_file = file;\r
// Print the Log header in the Rich text box.\r
displayLogHeader();\r
\r
- // Start a new thread which will montior and keep the log window up to date if required/\r
- startLogThread(read_file);\r
-\r
if (file == "dvdinfo.dat")\r
txt_log.Text = "Scan Log";\r
else if (file == "hb_encode_log.dat")\r
txt_log.Text = "Encode Log";\r
\r
-\r
- // When the window closes, we want to abort the monitor thread.\r
- this.Disposed += new EventHandler(forceQuit);\r
+ // Start a new thread which will montior and keep the log window up to date if required/\r
+ startLogThread(read_file); \r
}\r
\r
/// <summary>\r
/// <param name="file"> File which will be used to populate the Rich text box.</param>\r
private void startLogThread(string file)\r
{\r
- string logFile = Path.Combine(Path.GetTempPath(), file);\r
- if (File.Exists(logFile))\r
+ try\r
{\r
- // Start a new thread to run the autoUpdate process\r
- monitor = new Thread(autoUpdate);\r
- monitor.IsBackground = true;\r
- monitor.Start();\r
+ string logFile = Path.Combine(Path.GetTempPath(), file);\r
+ if (File.Exists(logFile))\r
+ {\r
+ // Start a new thread to run the autoUpdate process\r
+ monitor = new Thread(autoUpdate);\r
+ monitor.IsBackground = true;\r
+ monitor.Start();\r
+ }\r
+ else\r
+ rtf_actLog.AppendText("\n\n\nERROR: The log file could not be found. \nMaybe you cleared your system's tempory folder or maybe you just havn't run an encode yet. \nTried to find the log file in: " + logFile);\r
+\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("startLogThread(): Exception: \n" + exc);\r
}\r
- else\r
- rtf_actLog.AppendText("\n\n\nERROR: The log file could not be found. \nMaybe you cleared your system's tempory folder or maybe you just havn't run an encode yet. \nTried to find the log file in: " + logFile);\r
}\r
\r
/// <summary>\r
/// <param name="state"></param>\r
private void autoUpdate(object state)\r
{\r
- Boolean lastUpdate = false;\r
- updateTextFromThread();\r
- while (true)\r
+ try\r
{\r
- if ((mainWindow.isEncoding() == true) || (queueWindow.isEncoding() == true))\r
- updateTextFromThread();\r
- else\r
+ Boolean lastUpdate = false;\r
+ updateTextFromThread();\r
+ while (true)\r
{\r
- // The encode may just have stoped, so, refresh the log one more time before restarting it.\r
- if (lastUpdate == false)\r
+ if ((mainWindow.isEncoding() == true) || (queueWindow.isEncoding() == true))\r
updateTextFromThread();\r
-\r
- lastUpdate = true; // Prevents the log window from being updated when there is no encode going.\r
- position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused\r
+ else\r
+ {\r
+ // The encode may just have stoped, so, refresh the log one more time before restarting it.\r
+ if (lastUpdate == false)\r
+ updateTextFromThread();\r
+\r
+ lastUpdate = true; // Prevents the log window from being updated when there is no encode going.\r
+ position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused\r
+ }\r
+ Thread.Sleep(5000);\r
}\r
- Thread.Sleep(5000);\r
+ }\r
+ catch (ThreadAbortException)\r
+ {\r
+ // Do Nothing. This is needed since we run thread.abort(). \r
+ // Should probably find a better way of making this work at some point.\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("autoUpdate(): Exception: \n" + exc);\r
}\r
}\r
\r
/// </summary>\r
private void updateTextFromThread()\r
{\r
- string text = "";\r
- List<string> data = readFile();\r
- int count = data.Count;\r
-\r
- while (position < count)\r
+ try\r
{\r
- text = data[position].ToString();\r
- if (data[position].ToString().Contains("has exited"))\r
- text = "\n ############ End of Log ############## \n";\r
- position++;\r
+ string text = "";\r
+ List<string> data = readFile();\r
+ int count = data.Count;\r
+\r
+ while (position < count)\r
+ {\r
+ text = data[position].ToString();\r
+ if (data[position].ToString().Contains("has exited"))\r
+ text = "\n ############ End of Log ############## \n";\r
+ position++;\r
\r
- SetText(text);\r
+ SetText(text);\r
+ }\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show("updateTextFromThread(): Exception: \n" + exc);\r
}\r
}\r
\r
/// <param name="text"></param>\r
private void SetText(string text)\r
{\r
- // InvokeRequired required compares the thread ID of the\r
- // calling thread to the thread ID of the creating thread.\r
- // If these threads are different, it returns true.\r
- if (this.rtf_actLog.InvokeRequired)\r
+ try\r
{\r
- SetTextCallback d = new SetTextCallback(SetText);\r
- this.Invoke(d, new object[] { text });\r
+ // InvokeRequired required compares the thread ID of the\r
+ // calling thread to the thread ID of the creating thread.\r
+ // If these threads are different, it returns true.\r
+ if (this.IsHandleCreated) // Make sure the windows has a handle before doing anything\r
+ {\r
+ if (this.rtf_actLog.InvokeRequired)\r
+ {\r
+ SetTextCallback d = new SetTextCallback(SetText);\r
+ this.Invoke(d, new object[] { text });\r
+ }\r
+ else\r
+ this.rtf_actLog.AppendText(text);\r
+ }\r
}\r
- else\r
+ catch (Exception exc)\r
{\r
- this.rtf_actLog.AppendText(text);\r
+ MessageBox.Show("SetText(): Exception: \n" + exc);\r
}\r
}\r
\r
private void forceQuit(object sender, EventArgs e)\r
{\r
if (monitor != null)\r
- monitor.Abort();\r
+ {\r
+ while (monitor.IsAlive)\r
+ monitor.Abort();\r
+ }\r
\r
this.Close();\r
}\r