zoukankan      html  css  js  c++  java
  • winform 进程唯一,打开第二个激活第一个进程的窗体显示

       static class Program
        {
            public static EventWaitHandle ProgramStarted;
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                // 尝试创建一个命名事件
                bool isOnly;
                ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "OnlyStartEvent", out isOnly);
    
                // 如果该命名事件已经存在(存在有前一个运行实例),则发事件通知并退出
                if (!isOnly)
                {
                    ProgramStarted.Set();
                    return;
                }
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //处理未捕获的异常   
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常   
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常   
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
    
    
                Application.Run(new MainForm());
            }
        }

      public MainForm()
            {
                InitializeComponent();
                ThreadPool.RegisterWaitForSingleObject(Program.ProgramStarted, OnProgramStarted, null, -1, false);
                this.skinEngine1.SkinFile = AppDomain.CurrentDomain.BaseDirectory + "Skin/Skin.ssk";
            }
  • 相关阅读:
    redis list 清空记录小技巧
    fastJson 之 JSONPath使用
    【移动开发】怎样自己定义ViewGroup
    POJ 3255 Roadblocks
    java带图片的邮件发送方法实现
    android学习二(Activity)
    OpenWRT加入 crontab开机默认运行
    ubuntu14.04启动提示set_sw_state failed
    jekyll bootstrap更改主题theme
    windows API 实现截图
  • 原文地址:https://www.cnblogs.com/Iyce/p/4551075.html
Copyright © 2011-2022 走看看