in your main form under Main() method add the
following method-
[STAThread]
static void Main()
{
checkApplicationInstance();
}
then add the method -
static void checkApplicationInstance()
{
string currPrsName = Process.GetCurrentProcess().ProcessName;
Process[] allProcessWithThisName =
Process.GetProcessesByName(currPrsName);
if (allProcessWithThisName.Length > 1)
{
MessageBox.Show("your application is already
running\nor might be just restarting.\ntry again.",
"your app name", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
else
{
Application.Run(new mainForm());
}
}