只允许一个进程运行winform

static void Main() 
  
{
   
// get the name of our process
   string proc=Process.GetCurrentProcess().ProcessName;
   
// get the list of all processes by that name
   Process[] processes=Process.GetProcessesByName(proc);
   
// if there is more than one process
   if (processes.Length > 1)
   
{
    MessageBox.Show(
"Application is already running");
    
return;
   }
 else
                Application.Run(
new Form1());
  }

posted on 2007-01-29 15:48  玄新  阅读(262)  评论(0编辑  收藏  举报

导航