以下是选用用Mutex类有构函数.接着验证名称为SignletonWinApplication的互斥锁定是否存在.
代码贴下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool createNew;
Mutex mutex = new Mutex(false, "SignletonWinApplication", out createNew);
if (!createNew)
{
MessageBox.Show("该软件已经运行了!");
Application.Exit();
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}