Possible Duplicate:
What is the correct way to create a single instance application?
How can I check if my application is already open? If my application is already running, I want to show it instead of opening a new instance.
Here is one line code which will do this for you...
 if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
// Show your error message
}
                        public partial class App
    {
        private const string Guid = "250C5597-BA73-40DF-B2CF-DD644F044834";
        static readonly Mutex Mutex = new Mutex(true, "{" + Guid + "}");
        public App()
        {
            if (!Mutex.WaitOne(TimeSpan.Zero, true))
            {
                //already an instance running
                Application.Current.Shutdown();
            }
            else
            {
                //no instance running
            }
        }
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With