大伙帮忙看看以下代码,整个程序按Release编译通过,但点击运行bin\Release目录下的应用程序EXE文件,居然可以连续启动3个,第4个开始弹出消息“本程序已经启动了,不能再重复运行!”,啥原因?困惑中。。。
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool flag = false;
Mutex mutex = new Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out flag);
if (flag)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormStockTrading());
}
else
{
MessageBox.Show("本程序已经启动了,不能再重复运行!");
Environment.Exit(1);
}
}
}