WPF单例执行,防止同一个进程运行两次

C# App 代码如下:
using System.Threading;
using System.Reflection;

public partial class App : Application
{
    private static Mutex mutex = null; 
  protected override void OnStartup(StartupEventArgs e) { bool createdMutex; mutex = new Mutex(true, Assembly.GetExecutingAssembly().GetName().Name, out createdMutex); if (!createdMutex) { Current.Shutdown(); // 关闭当前实例 return; } base.OnStartup(e); } }

 

posted @ 2024-05-23 01:01  microsoft-zhcn  阅读(2)  评论(0编辑  收藏  举报