using System.Threading;
bool blnFirstInstance;
using (Mutex objMutex = new Mutex(false, "Local\\" + "<app name>", out blnFirstInstance))
{
if (!blnFirstInstance)
{
MessageBox.Show("<app name> is already running", "Single Use Only", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Application.Exit();
}
else
{
Application.Run(new Form1()); // or whatever your startup is...
}
}
Hi,
Please see my complete "Program.cs" below:
After I did this, it can still run more than one instance.
/////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace Ring_Buffer_Test
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool blnFirstInstance;
using (Mutex objMutex = new Mutex(false,"Local\\" +
"BokiTesting", out blnFirstInstance))
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (!blnFirstInstance)
{
MessageBox.Show("<app name> is already running", "Single
Use Only", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Application.Exit();
}
else
{
Application.Run(new Form1());
}
}
}
}
////////////////
I don't know why ...
Boki.