第一种方法:
private static void GetCheckProcess()
{
bool createNew;
using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out createNew))
{
if (createNew)
{
Application.Run(new ManagerComputer());
}
}
}
第二种方法:
string filename = Process.GetCurrentProcess().MainModule.FileName;
filename = System.IO.Path.GetFileNameWithoutExtension(filename);
Process[] pro = Process.GetProcessesByName(filename);
if (pro.Length == 0)
{
Application.Run(new ManagerComputer());
}怎样设置窗体只能启动一次呢?
最新推荐文章于 2024-07-03 21:34:01 发布
本文提供了两种检查当前应用程序是否已重复启动的方法。第一种方法利用Mutex类来实现互斥访问,确保仅有一个实例运行;第二种方法通过获取当前进程名称并搜索相同名称的进程是否存在来判断是否重复启动。
1139

被折叠的 条评论
为什么被折叠?



