WPF Enforce Single Instance Application

protected override void OnStartup(StartupEventArgs e)
{
// Single instance application logic

// Get Reference to the current Process
Process thisProc = Process.GetCurrentProcess();
// Check how many total processes have the same name as the current one
if (Process.GetProcessesByName(thisProc.ProcessName).Length > 1)
{
// If ther is more than one, than it is already running.
MessageBox.Show(“Application is already running.”, “Error”, MessageBoxButton.OK, MessageBoxImage.Stop);
Application.Current.Shutdown();
return;
}

// End single instance application logic

base.OnStartup(e);

//////DXSplashScreen.Show<SplashScreenView>();
//Thread.Sleep(5000);
DevExpress.Xpf.Core.ApplicationThemeHelper.UpdateApplicationThemeName();

Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException1;

InitModules();
}

Leave a Reply

Your email address will not be published. Required fields are marked *