如何只保留一个应用程序实例
2011-11-24 00:36
288 查看
直接贴代码,简单不用说明:
static class Program { ///<summary> /// The main entry point for the application. ///</summary> [STAThread] static void Main() { try { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //订阅ThreadException事件,处理UI线程异常,处理方法为 Application_ThreadException,关于事件的相关知识就不在这叙述了 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //订阅UnhandledException事件,处理非UI线程异常 ,处理方法为 CurrentDomain_UnhandledException AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //只允许一个应用程序实例 bool createdNew; Mutex mutex = new Mutex(false, "blackcore.editor.run", out createdNew); if (createdNew) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Default()); } } catch (Exception err) { MessageBox.Show(err.ToString()); } }
相关文章推荐
- 如何使应用程序只有一个实例在运行
- 如何使vc++窗口应用程序保持一个实例
- 如何让应用程序只有一个实例在运行
- 如何在MDI中使子窗体只保留一个实例
- 如何使应用程序只运行一个实例
- 如何在MDI中使子窗体只保留一个实例
- 如何在MDI中相同的子窗体只保留一个实例
- 如何让应用程序只有一个实例运行
- 如何使应用程序只运行一个实例
- [转载]如何在MDI中使子窗体只保留一个实例(反射方法)
- 关于"如何让应用程序只有一个实例在运行"的孟宪会的解决方法的疑问
- 如何在MDI中使子窗体只保留一个实例
- 如何让Qt应用程序只有一个实例
- 如何使应用程序只运行一个实例
- 如何让应用程序只有一个实例
- 如何让Qt应用程序只有一个实例
- C#如何让应用程序只有一个实例在运行
- (转)如何使应用程序只运行一个实例
- 在C# WinForm中如何使当前应用程序只允许启动一个实例
- 如何确保只有一个应用程序实例在运行?