您的位置:首页 > 编程语言

只允许程序运行一次的代码

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("已经有程序在运行!");

}

}

}

}

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