using System.Diagnostics;
using System.Reflection;
public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
//Loop through the running processes in with the same name
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
{
//Return the other process instance.
return process;
}
}
}
//No other instance was found, return null.
return null;
}
系统Main函数
if( RunningInstance() == null )
Application.Run(new yourFormName());
我用上面这种方法让程序只能产生一个实例,
我想做的是:如果程序已经运行,把它弹出并显示到最前面。
怎么实现 望高手指点!