怎样设置窗体只能启动一次呢?

来源:互联网 发布:贵金属走势图软件 编辑:程序博客网 时间:2024/05/19 14:02
 
第一种方法:  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());            }

原创粉丝点击