mutex有一个名字,如果这个exe已经打开了,createNew返回的就是false,程序就退出了。

这是个wpf application的例子     

protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            bool createdNew;
            Mutex mutex = new Mutex(true, "wpfapp28", out createdNew);
            if (createdNew)
            {

            }
            else
            {
                MessageBox.Show("already open");
                App.Current.Shutdown();
            }
        }

相关文章:

  • 2021-12-25
  • 2021-12-04
  • 2022-01-24
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
猜你喜欢
  • 2021-05-24
  • 2022-12-23
相关资源
相似解决方案