C# Mutex实现程序单实例运行
来源:互联网 发布:淘宝账号申诉二维码 编辑:程序博客网 时间:2024/04/29 11:54
简单实现
bool creatNew;Mutex mutex = new Mutex(true, "MutexTest_Instance", out creatNew);if (creatNew){//todo}elsereturn;
class Program { private static readonly string Read = "read"; private static readonly string Write = "write"; private static readonly int WaitTime = 1000 * 6 * 20; /// <summary> /// 程序部署两个版本计划任务方式执行(Read/Write) /// 同时只能有一个实例在运行 /// Write运行时,Read直接退出 /// Read运行时,Write等待Read结束再执行,直到超时 /// </summary> /// <param name="args"></param> static void Main(string[] args) { if (args.Length < 1) throw new ArgumentException("缺失命令行参数"); if (string.Compare(args[0], Read, true) == 0) { bool creatNew; Mutex mutex = new Mutex(true, "MutexTest_Instance", out creatNew); if (creatNew)//如果Mutex不存在则执行程序逻辑,否则退出 { bool waitOne = mutex.WaitOne(); if (waitOne) { // Read逻辑 mutex.ReleaseMutex(); } } else { } return; } if (string.Compare(args[0], Write, true) == 0) { bool creatNew; Mutex mutex = new Mutex(true, "MutexTest_Instance", out creatNew); bool waitOne = mutex.WaitOne(WaitTime); if (waitOne) { //Write逻辑 mutex.ReleaseMutex(); } else { //todo } return; } throw new ArgumentException("命令行参数有误"); } }
- C# Mutex实现程序单实例运行
- C#使用Mutex实现程序单实例运行
- 使用Mutex实现程序单实例运行(c#)
- 使用Mutex实现程序单实例运行(c#)
- 各种语言Mutex(互斥)实现程序单实例运行
- C#利用Mutex实现只运行一个程序实例
- C#利用Mutex实现只运行一个程序实例
- 利用Mutex实现应用程序的单实例运行
- 利用Mutex实现应用程序的单实例运行
- 利用Mutex实现应用程序的单实例运行
- 使用Mutex实现会话状态下单实例运行和系统范围内单实例运行
- 使用Mutex实现会话状态下单实例运行和系统范围内单实例运行
- c#WinForm 程序单实例运行并打开前一个实例(Mutex+API)
- C#单实例运行的实现
- C# 单实例运行
- c# 单实例运行
- 单实例运行程序
- 程序单实例运行
- 一道面试题:餐馆模拟
- dom4j在VisitorSupport类里删除属性抛出IndexOutOfBoundsException异常的解决方案
- 三种东西永远不要放到数据库里
- 使用ModelDriven接收参数添加用户
- 数据挖掘领域的十大经典算法
- C# Mutex实现程序单实例运行
- 写一段java代码让if else里面的语句都执行到
- 集合
- HDU 4037 Matrix 最小割模型转换
- 为什么要积分
- Source For perl
- poj1135 - Domino Effect
- uva 10400 - Game Show Math
- 如何判断一棵树是平衡二叉树