可以用
System.Diagnostics.GetProcesses()方法获取所有的启动进程名字, 如果发现多于一个就自动退出程序。
List<string> proList = new List<string>();
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist)
{
if (theprocess.ProcessName=="程序名字")
{
proList.Add(theprocess.ProcessName);
}
}
if (proList.Count>1)
{
MessageBox.Show("Already running");
this.Close();
}
把这个过程放到form_load里面就可以了。