zoukankan      html  css  js  c++  java
  • 如何只保留一个应用程序实例

    直接贴代码,简单不用说明:

        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());
    }
    }



  • 相关阅读:
    Codeforces Round #573 (Div. 2) C. Tokitsukaze and Discard Items
    Codeforces Round #573 (Div. 2) B
    练习2
    练习1
    上机练习4
    上机练习3
    上机练习1
    JAVA第一次作业
    es document的强制替换、创建、删除
    es 返回定制化的_source数据
  • 原文地址:https://www.cnblogs.com/blackcore/p/2261081.html
Copyright © 2011-2022 走看看