Visual Studio 2005(C#)中只允许一个实例运行的一种方法

Visual Studio 2005(C#)中只允许一个实例运行的一种方法
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace School.ReadPaperControl
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // 控制仅打开单实例进程
            if (System.Diagnostics.Process.GetProcessesByName

(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmControl());
            }
            esle
               messagebox.show("该程序已在运行","提示");
        }
    }
}

posted @ 2007-02-03 23:32  sunney  阅读(691)  评论(0编辑  收藏  举报