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;
}
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=E2A17727-765F-4346-8446-5D130622CB54
foreach(Form f in this.MdiChildren)
{
if (f is frmMeRpt)
{
f.Focus();
return;
}
}
frmMeRpt frmMert = new frmMeRpt();
frmMert.MdiParent = this;
frmMert.ShowDialog();
有关singleton 的例子,可以在以下链接中找到:
ms-help://MS.MSDNQTR.2003FEB.2052/cpqstart/html/cpsmpnetsamples-howtoremoting.htm#cpsmpSingletonSample