在入口文件Program.cs中添加如下代码:
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool Exist = false;
System.Diagnostics.Process CIP = System.Diagnostics.Process.GetCurrentProcess();
System.Diagnostics.Process[] CIPR = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process p in CIPR)
{
if (p.ProcessName == CIP.ProcessName && p.Id!=CIP.Id)
{
Exist = true;
}
}
if (Exist)
{
return;
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainInterface());
}
}
}