可以使用互斥体Mutex类型完成此功能。见如下代码:
    [STAThread]
    public static void Main(string[] args) 
    {
         //声明互斥体。
         Mutex mutex = new Mutex(false, "ThisShouldOnlyRunOnce");
         //判断互斥体是否使用中。
         bool Running = !mutex.WaitOne(0, false);
         if (! Running)
             Application.Run(new FormLogin());
         else
             MessageBox.Show("应用程序已经启动!");
    }

解决方案 »

  1.   

    http://www.pagediy.com/dispbbs.asp?boardID=2&ID=142
      

  2.   

    程序只运行一个实例
    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Reflection; public class OneInstnace
     { 
     [STAThread]
     public static void Main()
     {
     //Get the running instance.
     Process instance = RunningInstance();
     if (instance == null)
     {
     //There isn't another instance, show our form.
     Application.Run (new Form());
     }
     else
     {
     //There is another instance of this process.
     HandleRunningInstance(instance);
     }
     }
     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;
     }
     public static void HandleRunningInstance(Process instance)
     {
     //Make sure the window is not minimized or maximized
     ShowWindowAsync (instance.MainWindowHandle , WS_SHOWNORMAL);
     //Set the real intance to foreground window
     SetForegroundWindow (instance.MainWindowHandle);
     }
     [DllImport("User32.dll")] 
    private static extern bool ShowWindowAsync( IntPtr hWnd, int cmdShow);
     [DllImport("User32.dll")] private static extern bool
     SetForegroundWindow(IntPtr hWnd);
     private const int WS_SHOWNORMAL = 1;
    }
      

  3.   

    http://expert.csdn.net/Expert/topic/2572/2572209.xml?temp=.2559931
      

  4.   

    主要应用System.Diagnostics名字空间中的Process类来实现
    思路,我们在运行程序前,查找进程中是否有同名的进程,同时运行位置也相同,如是没有运行该程序,如果有,就将同名的同位置的程序窗口置前.主要代码:
    public static Process RunningInstance() 

    Process current = Process.GetCurrentProcess(); 
    Process[] processes = Process.GetProcessesByName (current.ProcessName); 
    //查找相同名称的进程 
    foreach (Process process in processes) 

    //忽略当前进程 
    if (process.Id != current.Id) 

    //确认相同进程的程序运行位置是否一样. 
    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName) 

    //Return the other process instance. 
    return process; 



    //No other instance was found, return null. 
    return null; 

     
      

  5.   

    示范程序下载位置
    http://free.yesky.com/servlet/mydown.yeskydown?tag=4&objID=85248
      

  6.   

    可以使用 Mutex 对象在线程之间以及跨进程进行同步。虽然 Mutex 不具备 Monitor 类的所有等待和脉冲功能,但它的确提供了创建可在进程之间使用的命名互斥的功能。
      

  7.   

    真长见识,我是用一个静态变量来判断的, 和  liduke(天下有雪) 一样