zoukankan      html  css  js  c++  java
  • wpf只运行一个实例

    首先 引用Microsoft.VisualBasic
    然后新建一个类 single
       public  class single:Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
        {
           App a;
           public single()
           {
               this.IsSingleInstance = true;
           }
           protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)
           {
               a = new App();
               a.InitializeComponent();
               a.Run();
               return false;
           }
           protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)
           {
               base.OnStartupNextInstance(eventArgs);
               a.activate();
           }
        }

    app.cs
        public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
                Window1 w = new Window1();
                w.Show();
            }
            public void activate()
            {
                MainWindow.Activate();
            }
            private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
            {
           
            }
            private void Application_Startup(object sender, StartupEventArgs e)
            {
             
            }
            private void Application_Exit(object sender, ExitEventArgs e)
            {
       
            }
        }
    app.g.cs
            [System.STAThreadAttribute()]
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public static void Main(string [] a ) {
                single s = new single();
                s.Run(a);  
            }

    from:http://social.msdn.microsoft.com/Forums/zh-SG/wpfzhchs/thread/afa0ad7c-3183-4d91-bcd3-dc89ddaee35a

  • 相关阅读:
    GCC的gcc和g++的区别
    C++运行程序依赖的环境-vcredist_x64.exe
    linux账户管理[转自vbird]
    Linux 的账号与群组[转自vbird]
    文件的搜寻【转vbird】
    常用的文件和目录操作命令【转vbird】
    十六进制查看器【转】
    文件与目录的默认权限与隐藏权限【转vbird】
    改变文件属性与权限(转)
    Linux目录规范和含义(转)
  • 原文地址:https://www.cnblogs.com/huzhenyu/p/2339165.html
Copyright © 2011-2022 走看看