2012年6月6日 星期三

C# 判斷程式執行 check if a process is running?

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
       if (System.Diagnostics.Process.GetProcessesByName(Application.ProductName).Length <= 1)
       {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          Application.Run(new Form1());
      }
      else
      {
         MessageBox.Show("running...");
      }
   }
}