/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
private static System.Threading.Mutex mutex;
protected override void OnStartup(StartupEventArgs e)
{
mutex = new System.Threading.Mutex(true, "OnlyRun_CRNS");
if (mutex.WaitOne(0, false))
{
base.OnStartup(e);
}
else
{
MessageBox.Show("程序已经在运行!", "提示");
this.Shutdown();
}
}
}
在App.xaml.cs中重写OnStartup实现,OnStartup可以做很多事情,例如:程序初始化、数据库初始化、命令行参数接收等。
WPF 防止程序多次打开运行
最新推荐文章于 2020-10-26 14:37:16 发布