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);
            }
        }
    
  • 相关阅读:
    CentOS 7.X 关闭SELinux
    删除或重命名文件夹和文件的方法
    centos7-每天定时备份 mysql数据库
    centos7 tar.gz zip 解压命令
    MySQL5.6/5.7/8.0版本授权用户远程连接
    下载CentOS7系统
    使用js实现tab页签切换效果
    sql优化常用的几种方法
    mysql 多表联查的快速查询(索引)
    【图论】强连通分量+tarjan算法
  • 原文地址:https://www.cnblogs.com/ysharp/p/2075143.html
Copyright © 2011-2022 走看看