C# 程序禁止重复启动
代码如下
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool bCanRun = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "anlogTestOne", out bCanRun);
if (!bCanRun)
{
MessageBox.Show("重复启动,程序已启动");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
注意其中的名称字符串需要注意,如果多个程序,需要修改为不同的id
参考链接
C# 程序禁止重复启动 - 抹茶大虾球丶 - 博客园 (cnblogs.com)https://www.cnblogs.com/seanyan/p/14028450.html特此记录
anlog
2023年2月26日