C#如何防止程序被重復打開
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
在程序的program.cs中,更改如下:
namespace form_repeat_open
{
static class Program
{
/// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
static void Main()
{
bool createNew;
using (Mutex mutex = new Mutex(true, Application.ProductName, out createNew))
{
if (createNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
mutex.ReleaseMutex();
}
else
{
MessageBox.Show("本程序已打開,禁止重復打開本程序!", "重復打開", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Thread.Sleep(500);
System.Environment.Exit(1);
}
}
}
}
}
該文章在 2021/3/29 22:59:01 編輯過 |
關鍵字查詢
相關文章
正在查詢... |