static void Main() 
{    //得到正在运行的例程 
     Process instance = RunningInstance(); 
     if(instance == null) 
     { 
AppStart.g_frmMain=new Form1();
context = new ApplicationContext();      
Application.Run(AppStart.g_frmMain);
     } 
     else 
    { 
//处理发现的例程 
HandleRunningInstance(instance); 
         //MessageBox.Show("当前程序已经运行了!"); 
     } 
}//不允许有两个程序同时启动
public static Process RunningInstance() 

     Process current = Process.GetCurrentProcess(); //这个怎么理解?获取的是当前线程?
     Process[] processes = Process.GetProcessesByName (current.ProcessName); //这又是什么?
     //遍历正在有相同名字运行的例程 
     foreach (Process process in processes)
    { 
//忽略现有的例程 
       if (process.Id != current.Id) //这里就是在判断current.Id与processes.Id即(current.ProcessName),上面不是把current.ProcessName存进去了?那不是一定会不成立一次。
       { 
//确保例程从EXE文件运行 
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName) 
        { 
          //返回另一个例程实例 
 return process; 

        } 
     } 
//没有其它的例程,返回Null 
return null; 

public static void HandleRunningInstance(Process instance) 

//确保窗口没有被最小化或最大化 
ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL); 
设置真实例程为foreground window 
SetForegroundWindow (instance.MainWindowHandle); 
} ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL); 
该函数设置由不同线程产生的窗口的显示状态
SetForegroundWindow (instance.MainWindowHandle); 
该函数将创建指定窗口的线程设置到前台这里两个怎么不让运行同一个程序?怎么看都是在显示窗体