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";
            }
  • 相关阅读:
    sell学习
    redis安装
    [Yii Framework] Share the session with memcache in Yii
    CentOS 网络设置修改
    虚拟机的几种网络方式详解
    linux命令小技巧
    交叉编译: 常见参数配置
    Extend volumn in ubuntu 14.04
    OpenCV 2.4.13 installed in Ubuntu 14 and CMakeLists Demo
    CMake: Cross-Platform Compling
  • 原文地址:https://www.cnblogs.com/Iyce/p/4551075.html
Copyright © 2011-2022 走看看