Skip to content

Instantly share code, notes, and snippets.

@follesoe
Created December 24, 2010 14:39
Show Gist options
  • Save follesoe/754294 to your computer and use it in GitHub Desktop.
Save follesoe/754294 to your computer and use it in GitHub Desktop.
Using protocol handlers as a ultra thin layer of integration
/// <summary>
/// The Main class of the application.
/// </summary>
static class Program
{
// Private members
private static MainForm mainForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Creates a new SingleInstanceApplication (from the VB Namespace)
SingleInstanceApplication app = new SingleInstanceApplication();
app.StartupNextInstance += new StartupNextInstanceEventHandler(app_StartupNextInstance);
//Creates the MainForm and loads the application.
mainForm = new MainForm();
app.Run(mainForm);
}
/// <summary>
/// Method executed if the application is allready running.
/// </summary>
static void app_StartupNextInstance(object sender, StartupNextInstanceEventArgs e)
{
//Tels the loaded main form to parse the command line arguments.
List<string> list = new List<string>(e.CommandLine);
mainForm.ParseCommandLine(list.ToArray());
}
}
/// <summary>
/// A SingleInstanceApplication extending the application base. Part of the VB namespaces.
/// </summary>
public class SingleInstanceApplication : WindowsFormsApplicationBase
{
public SingleInstanceApplication(AuthenticationMode mode) : base(mode)
{
InitializeAppProperties();
}
public SingleInstanceApplication()
{
InitializeAppProperties();
}
protected virtual void InitializeAppProperties()
{
this.IsSingleInstance = true;
this.EnableVisualStyles = true;
}
public virtual void Run(MainForm mainForm)
{
List<string> list = new List<string>(this.CommandLineArgs);
mainForm.ParseCommandLine(list.ToArray());
this.MainForm = mainForm;
this.Run(list.ToArray());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment