zoukankan      html  css  js  c++  java
  • C# winform只允许程序运行一个

    C# winform只允许程序运行一个 ,修改主入口文件。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace PCShutDown
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
    
                bool createdNew;//返回是否赋予了使用线程的互斥体初始所属权 
                System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量 
                if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体 
                {
                    Application.Run(new MainFrm());
                    instance.ReleaseMutex();
                }
                else
                {
                    MessageBox.Show("已经有一个程序已经在运行,请不要同时运行多个程序!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
    
              
            }
        }
    
    
        
    
    }
    

      

  • 相关阅读:
    基于MongoDB.Driver的扩展
    通用查询设计思想
    API接口通讯参数规范
    lambda简单记录
    list去重精简代码版
    spring boot file上传
    fastjson过滤器简单记录
    java读取properties文件
    list循环删除单个元素
    MapReduce运行流程分析
  • 原文地址:https://www.cnblogs.com/nymz/p/14206497.html
Copyright © 2011-2022 走看看