在启动对象类中Program.cs添加如下如下限制即可:
using System.Threading;
[STAThread]
static void Main()
{
bool create;
using (Mutex mu = new Mutex(true, Application.ProductName, out create))
{
if (create)
{
Run();
}
else
{
MessageBox.Show("程序已经运行!");
}
}
}
/// <summary>
/// 启动程序
/// </summary>
static void Run()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm ());
}
[STAThread]
static void Main()
{
bool create;
using (Mutex mu = new Mutex(true, Application.ProductName, out create))
{
if (create)
{
Run();
}
else
{
MessageBox.Show("程序已经运行!");
}
}
}
/// <summary>
/// 启动程序
/// </summary>
static void Run()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm ());
}