From d15bd0acc033ba300b94ed9e0d91a197a3eaf833 Mon Sep 17 00:00:00 2001 From: Christian Rondeau Date: Fri, 25 Jul 2014 14:15:53 -0400 Subject: [PATCH] Allow only one instance --- GoToWindow/Program.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/GoToWindow/Program.cs b/GoToWindow/Program.cs index b5aa6ca..36e5f75 100644 --- a/GoToWindow/Program.cs +++ b/GoToWindow/Program.cs @@ -1,16 +1,23 @@ using System; +using System.Threading; using System.Windows.Forms; namespace GoToWindow { - static class Program + internal static class Program { [STAThread] - static void Main() + private static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new GoToWindowApplicationContext()); + bool createdNew; + using (new Mutex(true, "GoToWindow", out createdNew)) + { + if (!createdNew) return; + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new GoToWindowApplicationContext()); + } } } }