您的位置:首页 > 其它

让程序只能运行一次

2013-09-29 15:58 176 查看
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace frameTest
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
string MName = Process.GetCurrentProcess().MainModule.ModuleName;
string PName = Path.GetFileNameWithoutExtension(MName);
Process[] myProccess = Process.GetProcessesByName(PName);
if (myProccess.Length > 1)
{
MessageBox.Show("程序已经运行,不能重复打开", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
else
{

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: