using System; using System.Windows.Forms; namespace OTSMeasureApp { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { //--------------------------只运行一个测量程序-------------------------------- bool flag = false; System.Threading.Mutex mutex = new System.Threading.Mutex(true, "OTSIncAMeasureApp", out flag); //第一个参数:true--给调用线程赋予互斥体的初始所属权 //第一个参数:互斥体的名称 //第三个参数:返回值,如果调用线程已被授予互斥体的初始所属权,则返回true if (!flag) { MessageBox.Show("Only one measurement program can be run!", "please confirm", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Environment.Exit(0);//退出程序 } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new OTSIncAMeasureAppForm()); } } }