设置程序只能开一个,若重复打开给出提示说已经又程序在运行

来源:互联网 发布:c 并行与分布式编程 编辑:程序博客网 时间:2024/06/05 11:35

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

namespace BT.DataAssist
{
static class Program
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
bool bCreatedNew;
Mutex m = new Mutex(false, “BT.DataAssist”, out bCreatedNew);
if (bCreatedNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
}
else
{
MessageBox.Show(“已经有相同的实例在运行。”, “系统提示”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}

原创粉丝点击