您的位置:首页 > 编程语言 > C#

C# 禁止程序多个实例运行

2013-09-17 09:03 218 查看
//program.cs
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool ret = false;
System.Threading.Mutex running = new System.Threading.Mutex(true, Application.ProductName, out ret);
if (ret)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain());
running.ReleaseMutex();
}
else
{
MessageBox.Show("程序已经在运行,请不要同时运行多个本程序!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: