Skip to content

Instantly share code, notes, and snippets.

@ridomin
Created November 1, 2017 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridomin/5ac09e0c2598f936170f4d58f486d85c to your computer and use it in GitHub Desktop.
Save ridomin/5ac09e0c2598f936170f4d58f486d85c to your computer and use it in GitHub Desktop.
namespace Rido.SingleInstance
{
public class SingleInstanceManager<T> : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
where T: System.Windows.Application, new()
{
T app;
public SingleInstanceManager()
{
base.IsSingleInstance = true;
}
protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
app = new T();
app.Run();
return false;
}
protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs e)
{
app.MainWindow.Activate();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment