Skip to content

Instantly share code, notes, and snippets.

@dbuksbaum
Created January 11, 2012 19:47
Show Gist options
  • Save dbuksbaum/1596414 to your computer and use it in GitHub Desktop.
Save dbuksbaum/1596414 to your computer and use it in GitHub Desktop.
SingleInstanceManager
using System;
using System.Linq;
using System.Windows;
using Microsoft.VisualBasic.ApplicationServices;
using StartupEventArgs = Microsoft.VisualBasic.ApplicationServices.StartupEventArgs;
namespace Utility
{
public class SingleInstanceManager : WindowsFormsApplicationBase
{
[STAThread]
public static void Main(string[] args)
{
var manager = new SingleInstanceManager();
manager.Run(args);
}
public SingleInstanceManager()
{
IsSingleInstance = true;
}
protected override bool OnStartup(StartupEventArgs eventArgs)
{
Loader.Start();
return false;
}
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
{
base.OnStartupNextInstance(eventArgs);
((App)Application.Current).HandleArguments(eventArgs.CommandLine.ToArray());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment