Hi everyone,
I'm using WPF to make a nice UI for a completely automated system (to the point where there are no interactive controls what-so-ever) that downloads media from the net and learns from it. I've got a class that I've created which acts as an entry point to the entire system, as listed below. My question is, in the Startup method, should I wrap the entire method in a Thread and use Dispatchers to show/hide the window, or should I go about it a different way? The ATHENAProgram class has a single method, Run, which should be able to interact with the system window in a seperate thread (so that any long-running processes within the ATHENAProgram don't freeze the system).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATHENA.Platform.UI;
namespace ATHENA.Platform.System
{
public class ATHENASystem
{
/// <summary>
/// Starts the specified program (this is the system's entry point).
/// </summary>
/// <param name="program">the program to run.</param>
/// <param name="debugMode">true for debug mode.</param>
public static void Startup(ATHENAProgram program, bool debugMode)
{
ATHENASystemWindow systemWindow = new ATHENASystemWindow();
ATHENASystem system = new ATHENASystem(systemWindow, debugMode);
systemWindow.Show();
program.Run(system);
systemWindow.Close();
}
// Fields.
private ATHENASystemWindow m_systemWindow;
private bool m_debugMode;
/// <summary>
/// Creates an instance of the system.
/// </summary>
/// <param name="systemWindow">the system window to interact with.</param>
/// <param name="debugMode">true for debug mode.</param>
private ATHENASystem(ATHENASystemWindow systemWindow, bool debugMode)
{
m_systemWindow = systemWindow;
m_debugMode = debugMode;
}
/// <summary>
/// Writes text to the console.
/// </summary>
/// <param name="text">the text to write.</param>
/// <param name="bold">true for bold text.</param>
/// <param name="italic">true for italic text.</param>
/// <param name="underline">true for underlined text.</param>
public void Write(string text, bool bold, bool italic, bool underline)
{
m_systemWindow.Console.Write(text, bold, italic, underline);
}
/// <summary>
/// Writes text to the console if the system is in debug mode.
/// </summary>
/// <param name="text">the text to write.</param>
/// <param name="bold">true for bold text.</param>
/// <param name="italic">true for italic text.</param>
/// <param name="underline">true for underlined text.</param>
public void DebugWrite(string text, bool bold, bool italic, bool underline)
{
if (m_debugMode) Write(text, bold, italic, underline);
}
}
}
P.S. Write(...) and DebugWrite(...) are thread-safe (i.e. they update the UI with delegates).