只允许程序运行一次的代码
2013-02-18 14:53
295 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
namespace RunOnce
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool createNew = false;
using (new Semaphore(0, 1, "MyAppIdentify", out createNew))
{
if (createNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("已经有程序在运行!");
}
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
namespace RunOnce
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool createNew = false;
using (new Semaphore(0, 1, "MyAppIdentify", out createNew))
{
if (createNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("已经有程序在运行!");
}
}
}
}
}
相关文章推荐
- VC程序只允许运行一次
- 只允许一个程序运行一个实例 代码
- 让一个程序运行一次,在它运行时,不允许再启动一个新的进程。
- winform 里同一个程序只允许运行一次
- 程序只允许运行一次
- 仅允许程序运行一个实例代码实现
- C# 程序只允许运行一个实例的正确代码
- 程序只运行一次并激活原来的程序
- 求助操作系统启动,自动运行程序,用DELPHI 要怎么写代码?
- 我工作这几年(五)-- 在代码中加入一些关键统计信息来实时监控程序的运行状态
- hello程序的一次运行
- 嵌入式程序设计中运行速度与代码尺寸优化策略
- 保证某段代码在程序的生命周期内只执行一次
- 程序只运行一次并激活原来的程序 (转载 csdn linzhenqun)
- c# 仿照计划任务(定时提示、定时运行程序、定时打开url(前台/后台))/每天/每周/每月/一次 多时间段
- 简单代码实现C#中运行另外一个程序
- PB运行的程序只能运行一次
- [代码]Delphi实现检测程序是否在VMWare中运行
- Linux环境下C++只允许单个程序运行
- Delphi实现程序只运行一次并激活已打开的程序