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

  • 相关阅读:
    tp5的 LayUI分页样式实现
    BSBuDeJie_05
    WCF 程序入门
    iOS Xcode 调试技巧
    Visual Studio 2015 如何将全英界面转成中文
    BSBuDeJie_04
    BSBuDeJie_03
    BSBuDeJie_02
    BSBuDeJie_01
    iOS 一些琐碎的知识点
  • 原文地址:https://www.cnblogs.com/huzhenyu/p/2339165.html
Copyright © 2011-2022 走看看