首页 > 代码库 > mutex 实现 只允许一个进程

mutex 实现 只允许一个进程

 

  static class Program    {        [STAThread]        static void Main()        {            bool createdNew=false;            Mutex mutex = new Mutex(true, @"Global\AirVoice", out createdNew);            try            {                if (createdNew)                {                    Application.EnableVisualStyles();                    Application.SetCompatibleTextRenderingDefault(false);                    LoginForm loginForm = new LoginForm();                    if (loginForm.ShowDialog() != DialogResult.OK)                    {                        return;                    }                    IMultimediaManager multimediaManager = MultimediaManagerFactory.GetSingleton();                    multimediaManager.CameraDeviceIndex = 0;                    multimediaManager.MicrophoneDeviceIndex = 0;                    multimediaManager.AutoAdjustCameraEncodeQuality = false;                    multimediaManager.CameraEncodeQuality = 0;                    multimediaManager.ChannelMode = ChannelMode.P2PChannelFirst;                    multimediaManager.Initialize(loginForm.CurrentUserID, loginForm.CurrentPwd, ConfigurationManager.AppSettings["ServerIP"], int.Parse(ConfigurationManager.AppSettings["ServerPort"]));                    multimediaManager.AllowControlDesktop = false;                    multimediaManager.OutputDesktop = false;                    MainForm mainForm = new MainForm();                    mainForm.Initialize(multimediaManager, loginForm.CurrentUserID);                    Application.Run(mainForm);                }            }            catch (Exception ee)            {                MessageBox.Show(ee.Message + "," + ee.StackTrace);            }finally            {                mutex.ReleaseMutex();                            }        }    }
View Code

 

mutex 实现 只允许一个进程