Tuesday, September 27, 2011

Avoid Running of Multiple Instances of application


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
             
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool ok;
            System.Threading.Mutex m = new System.Threading.Mutex(true, "Tool Name", out ok);

            if (!ok)
            {
                MessageBox.Show("Another instance is already running.", "Tool Name");
                return;
            }

            // Do some stuff here...
            Application.Run(new ToolName());
            GC.KeepAlive(m);

No comments:

Post a Comment