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);
            }
        }
    
  • 相关阅读:
    多线程编程(一)
    所谓费曼学习法
    Java 基本数据类型扩充
    好记性不如烂笔头
    Java_面试札记
    Stream替代for-编码五分钟-划水五小时
    为什么启动线程是start方法?
    Java面试札记
    Tree
    手写SpringMVC 框架
  • 原文地址:https://www.cnblogs.com/ysharp/p/2075143.html
Copyright © 2011-2022 走看看