遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

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

 

posted on 2014-09-27 16:07  遗忘海岸  阅读(810)  评论(0编辑  收藏  举报