如何使一个Windows应用程序只运行一个实例,看如下代码:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
namespace MyMonitor
{
static class Program
{
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Process[] ps = Process.GetProcessesByName(Process
.GetCurrentProcess().ProcessName);
if (ps.Length <= 1)
{
Application.EnableVisualStyles();
Application
.SetCompatibleTextRenderingDefault(false);
Application.Run(new EMonitor());
}
else
{
MessageBox.Show("不能打开多于一个程序实例!");
}
}
}
}
using Sys