日期:2014-05-18 浏览次数:21220 次
static void Main()
{
bool runone;
System.Threading.Mutex run = new System.Threading.Mutex(true, "xinbiao_a_test", out runone);
if (runone)
{
run.ReleaseMutex();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("已经运行了一个实例了。");
//如何获取这个已经运行的实例呢????
}
}
System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process thisprocess in allProcess)
{
string processName = thisprocess.ProcessName;
if (processName.ToLower() == "进程名字")
{
try
{
//LZ在这操作你要操作的东西
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return;
}
}
}