C# Single WinApp instance

By admin - Last updated: Thursday, November 1, 2007 - Save & Share - Leave a Comment
using System.Threading;
static void Main()
{
  bool isFirstInstance;
  Mutex mutex =
     new Mutex(true, "Global\\" + “App_Name_Here”, out isFirstInstance);

  if(isFirstInstance)
    Application.Run(new YourAppMainClass());
  else
    MessageBox.Show("There is already an instance running.",
        "Warning",
        MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
        MessageBoxDefaultButton.Buttonx);
}



Posted in Code Notes • • Top Of Page