using System;
using System.Windows.Forms;
using System.Threading;
namespace SingleInstanceApp
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Mutex objMutex = null;
const string MutexName = "THEONE";
try
{
//Open Mutex if already exists
objMutex = Mutex.OpenExisting(MutexName);
}
catch (WaitHandleCannotBeOpenedException)
{
//Cannot be opened because no Mutex exists
}
if (objMutex == null)
{
//Create a new instance of Mutex
objMutex = new Mutex(true, MutexName);
}
else
{
//Close Mutex because one instance already exists
objMutex.Close();
return;
}
Application.Run(new MainForm());
}
}
}
No comments:
Post a Comment