Code
static class Program
{
public static MainForm mainForm;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool initiallyOwned = true;
bool isCreated;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Mutex m = new Mutex(initiallyOwned, "14E260D2-A7E8-43b8-9ECD-2A426FAA79B9", out isCreated);
if (!(initiallyOwned && isCreated))
{
MessageBox.Show("软件已经在运行中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
else
{
Application.Run(new mainForm());
}
}
}
c#学习笔记 只运行一个实例
Code