织梦CMS - 轻松建站从此开始!

罗索

当前位置: 主页>杂项技术>.NET(C#)>

让你的程序同时只能运行一个实例

罗索客 发布于 2008-07-29 09:58 点击:次 
让你的程序同时只能运行一个实例
TAG:

让你的程序同时只能运行一个实例

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace StressSync
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool bCreatedNew;
string strApp = System.Windows.Forms.Application.ExecutablePath;
strApp = strApp.Replace("\\\\", "").Replace(":", "");
System.Threading.Mutex mutex = new System.Threading.Mutex(true, strApp, out bCreatedNew);
if (!bCreatedNew)
{
//program alread run
MessageBox.Show("您已经运行了本程序,请确认!","警告",MessageBoxButtons.OK, MessageBoxIcon.Warning);
Environment.Exit(1);
}

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
}
}
}

(ixmy)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200807/7094.html]
本文出处:网络博客 作者:ixmy
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容