C# 中让Windows窗体只运行一次

发布时间:2009年08月10日      浏览次数:729 次
方法一:
[STAThread]
static void Main() { bool isAppRunning = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(
true,
System.Diagnostics.Process.GetCurrentProcess().ProcessName,
out isAppRunning);
if (!isAppRunning)
{
MessageBox.Show("本程序已经在运行了,请不要重复运行!");
Environment.Exit(1);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
注:也可以这样设置Mutex , Mutex MyMutex = new Mutex(true, "OnlyRunOncetime", out bExist);
确保唯一。
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!