zoukankan      html  css  js  c++  java
  • 单实例 winform zz

    (引用了 Microsoft.VisualBasic.ApplicationServices)
    SingleInstanceApplicationWrapper.cs

    using System.Windows.Forms;
    using Microsoft.VisualBasic.ApplicationServices;
     
    namespace Highflyer
    {
        /// <summary>
        /// 单实例应用程序封装类
        /// </summary>
        public class SingleInstanceApplicationWrapper : WindowsFormsApplicationBase
        {
            private readonly Form mainForm;
     
            public SingleInstanceApplicationWrapper(Form form)
            {
                mainForm = form;
    #if DEBUG
                this.IsSingleInstance = false;
    #endif
    #if RELEASE
                this.IsSingleInstance = true;
    #endif
            }
     
            protected override bool OnStartup(StartupEventArgs e)
            {
                Application.Run(mainForm);
                return false;
            }
     
            protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e)
            {
                // 这里可以把本次使用的参数传给之前的实例,本人在一个WPF 屏幕键盘项目里传送了键盘显示方式(数字、英文、手写)参数
                //e.BringToForeground = true;
                //if (e.CommandLine.Count > 0)
                //{
                //  app.DealArgs(e.CommandLine.ToArray());
                //}
            }
        }
    }
    View Code

    Program.cs

    using System;
    using System.Windows.Forms;
    using Highflyer;
     
    namespace Eparcar.ParkLocal.GateBoxClient
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
     
                MainForm mainForm = new MainForm();
                SingleInstanceApplicationWrapper wrapper = new SingleInstanceApplicationWrapper(mainForm);
                wrapper.Run(args);
            }
        }
    }
    View Code
  • 相关阅读:
    解決 Android Studio 不停 Indexing 的問題(Updating Indices: Indexing paused due to batch update)
    通过某个关键字排序一个字典列表
    django cmes 后台管理
    python 处理音视频
    python 加密
    PyEngine3D
    获取单词列表出现频率最高的单词
    django 上传文件
    python之MD5加密
    切片对象的demo
  • 原文地址:https://www.cnblogs.com/zeroone/p/3371451.html
Copyright © 2011-2022 走看看