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); } }