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);
            }
        }
    
  • 相关阅读:
    xcode8.3 shell 自动打包脚本
    MarkDown常用语法记录
    正则表达式matcher.group()用法
    使用Jenkins进行持续集成
    Java8新特性:Stream的使用
    zookeeper windows 下配置和基础命令
    JAVA文件中获取路径及WEB应用程序获取路径方法
    共享锁(S锁)和排它锁(X锁)
    zookeeper 官方文档——综述
    zookeeper 入门指导
  • 原文地址:https://www.cnblogs.com/ysharp/p/2075143.html
Copyright © 2011-2022 走看看