zoukankan      html  css  js  c++  java
  • Single Instance Application

    C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.VisualBasic.dll

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    
    namespace PGPowerPoint_ListTool
    {
        class SingleInstanceApplicationWrapper:Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
        {
            private PGPAPP app;
            public SingleInstanceApplicationWrapper()
            {
                this.IsSingleInstance = true;
            }
            protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)
            {
                app = new PGPAPP();
                app.Run();
                return false;
            }
            protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)
            {
                if (eventArgs.CommandLine.Count > 0)
                {
                    app.ShowDocument(eventArgs.CommandLine[0]);
                }
                else
                {
                    app.MainWindow.Activate();
                    MessageBox.Show(app.MainWindow, "More than 1 instance of this application is not allowed"); 
                   
                }
            }
        }
    }
    
        public partial class App : Application
        {
            protected override void OnStartup(StartupEventArgs e)
            {
                base.OnStartup(e);
                MainWindow main = new MainWindow();
                MainWindow = main;
                main.Show();
    
                if (e.Args.Length > 0) ShowDocument(e.Args[0]);
            }
    
            public void ShowDocument(string str)
            {
                ((ListToolViewModel)MainWindow.DataContext).SerializeTheList(str);
            }
        }
    
        class StartUp
        {
            [STAThread]
            public static void Main(string[] args)
            {
                SingleInstanceApplicationWrapper wrapper = new SingleInstanceApplicationWrapper();
                wrapper.Run(args);
            }
        }
    
  • 相关阅读:
    github首页添加README.md
    uni-app 使用问题记录
    rgb转16进制js方法,npm插件
    升级vue3注意事项记录 vue3都需要升级些什么
    获取当前网页的协议+域名(兼容IE)
    C++ 真随机
    vue打包后反编译到源代码(reverse-sourcemap)(转载)
    vue导出页面为pdf文件
    设计模式总结
    访问者模式
  • 原文地址:https://www.cnblogs.com/ysharp/p/2075143.html
Copyright © 2011-2022 走看看