WPF简介与XAML语言
7///<summary>
8/// Interaction logic for App.xaml
9///</summary>
10publicpartialclass App : Application
11 {
12 Mutex mutex=null;
13protectedoverridevoid OnStartup(StartupEventArgs e)
14 {
15base.OnStartup(e);
16bool createdNew = false;
17 mutex = new Mutex(true, "WPFLifeCycle",out createdNew); 18if (!createdNew)
19 {
20 MessageBox.Show("程序正在运行中,无法启动另一个实例!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning); 21this.Shutdown();
22 }
23 }
24 }
25}
此时如果我们已经运行了WPFLifeCycle.exe,当再双击此应用则会给出提示: