为了账号安全,请及时绑定邮箱和手机立即绑定

使用Mutex运行应用程序的单个实例

使用Mutex运行应用程序的单个实例

C#
犯罪嫌疑人X 2019-08-13 15:47:09
使用Mutex运行应用程序的单个实例为了只允许运行应用程序的单个实例,我正在使用互斥锁。代码如下。这是正确的方法吗?代码中是否有任何缺陷?当用户第二次尝试打开应用程序时,如何显示已在运行的应用程序。目前(在下面的代码中),我只是显示另一个实例已在运行的消息。    static void Main(string[] args)     {         Mutex _mut = null;         try         {             _mut = Mutex.OpenExisting(AppDomain.CurrentDomain.FriendlyName);         }         catch         {              //handler to be written         }         if (_mut == null)         {             _mut = new Mutex(false, AppDomain.CurrentDomain.FriendlyName);         }         else         {             _mut.Close();             MessageBox.Show("Instance already running");         }                 }
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 407 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信