zoukankan      html  css  js  c++  java
  • WPF外包公司—技术分享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);  
            }
     

  • 相关阅读:
    CentOS 7下搭建配置SVN服务器
    centos7 安装字体库
    redis 开机自启动
    Firewalls
    当安装某个扩展提示错误,显示版本冲突的时候,
    防盗链
    Telnet ping不通443的解决办法
    R处理xml文件
    解决load 函数无法赋予变量名的问题
    用Rprofile文件配置打开时R的设置
  • 原文地址:https://www.cnblogs.com/dotfun/p/2688119.html
Copyright © 2011-2022 走看看