让WinFrom窗体应用程序只能打开一个
static class Program
{
public static bool isRestarts { get; set; } = false;//是否重启或开机
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
System.Threading.Thread.Sleep(3000);//如果有其他子程序没关闭完,可以设置延时,让上一次的程序彻底关闭在启动
SysHelper.RunFrmOnly<Form1>();
if (isRestarts)//如果当前进程没有该程序,则开启自己所需要的程序
{
//如果有子程序可以这里打开,无则不作操作
Application.Run(new Form1());
}
}
}
public static class SysHelper
{
/// <summary>
/// 唯一运行一个实例,第二次打开时会把首次运行的置顶
/// 缺陷:(1)应用程序改名后无效 (2)如果首次运行的界面最大化,置顶时,界面会缩小,需要手动调整
/// </summary>
/// <typ