【Winfrom-禁止重复启动程序】 程序不能重复启动
2024-09-05 16:56:27
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Demo
{
static class Program
{
/// <summary>
/// 用于判断程序是否有重复启动的互斥量
/// </summary>
static System.Threading.Mutex _mutex; /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{ //是否可以打开新进程
bool createNew; /// 获取程序集Guid作为唯一标识,禁止程序重复启动
Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
string guid = ((GuidAttribute)guid_attr).Value;
_mutex = new System.Threading.Mutex(true, guid, out createNew); if (false == createNew)
{
MessageBox.Show("程序已在本机运行,不能重复运行!", "系统消息");
Application.Exit();
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
_mutex.ReleaseMutex();
Application.Run(new FrmMain());
}
}
}
}
最新文章
- WPF的路由事件、冒泡事件、隧道事件(预览事件)
- 抛弃msvcrtXX库
- kafka_2.11-0.8.2.2的搭建
- 【Sqlserver】修改数据库表中的数据:对缺失的数据根据已有的数据进行修补
- u-boot Makefile Source Test
- Winform Windows Media Player 简易播放器 分类: WinForm 2014-07-31 20:12 589人阅读 评论(0) 收藏
- Linux下运行C++程序出现";段错误(核心已转储)";的原因
- 2048 Puzzle游戏攻略
- 倒计时(距离活动结束还有X天X小时X分X秒)
- Centos7安装Percona5.7
- npm常用命令及版本号浅析
- jvm性能优化及内存分区
- 【转】Reflector、reflexil、De4Dot、IL相关操作指令合集
- IC5141安装备忘
- 如何使用Ubuntu中的avdManager命令行为“System-Image;Androd-27;GoogleAPI;x86”创建一个AVD?
- mysql中查看数据库的版本,什么版本
- 超全面的JavaWeb笔记day23<;AJAX>;
- cf1088D. Ehab and another another xor problem(思维)
- Apache Spark 2.0三种API的传说:RDD、DataFrame和Dataset
- tp.c