110,534
社区成员
发帖
与我相关
我的任务
分享
static class Program
{
public static System.Threading.Mutex Run;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool noRun = false;
Run = new System.Threading.Mutex(true, "HumControl", out noRun);
//检测是否已经运行
if (noRun)
{//未运行
Run.ReleaseMutex();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
else
{//已经运行
//MessageBox.Show("已经有一个实例正在运行!");
//切换到已打开的实例
}
}
}
DialogResult _dlgResult;
_dlgResult = MessageBox.Show("保存设置成功,需要重新启动应用程序后生效。\r\n立即重新启动程序?",
"提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (_dlgResult == DialogResult.OK)
{
Program.Run.Close();
Application.Restart();
}
new System.Threading.Mutex(true, Application.ProductName).ReleaseMutex();
Application.Restart();