<Application x:Class="SingleInstanceSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
</Application.Resources>
</Application>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;
using System.Threading;
using System.Reflection;
namespace SingleInstanceSample {
public partial class App : System.Windows.Application {
Mutex mutex;
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
string mutexName = "MyCompanyName.MyAppName";
bool createdNew;
mutex = new Mutex(true, mutexName, out createdNew);
if( !createdNew ) { Shutdown(); }
}
}
}
|