From 181496912f18897c957ef932899c713b7413ecd2 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 8 Mar 2012 23:25:37 +0000 Subject: [PATCH] windows: only allow one SparkleShare instance at a time --- SparkleShare/Program.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/SparkleShare/Program.cs b/SparkleShare/Program.cs index 0a2558fe..89ba64f4 100644 --- a/SparkleShare/Program.cs +++ b/SparkleShare/Program.cs @@ -16,6 +16,7 @@ using System; +using System.Threading; #if __MonoCS__ using Mono.Unix; @@ -29,8 +30,10 @@ namespace SparkleShare { public static SparkleController Controller; public static SparkleUI UI; - - + + public static Mutex ProgramMutex = new Mutex (false, "SparkleShare"); + + // Short alias for the translations public static string _ (string s) { @@ -66,7 +69,14 @@ namespace SparkleShare { if (show_help) ShowHelp (option_set); - + + // Only allow one instance of SparkleShare + if (!ProgramMutex.WaitOne (0, false)) { + Console.WriteLine ("SparkleShare is already running."); + Environment.Exit (-1); + } + + // Initialize the controller this way so that // there aren't any exceptions in the OS specific UI's Controller = new SparkleController ();