Prevent multiple instances of wpf application
How to build a single instance application in WPF.
In a wpf application, How could I prevent opening multiple windows ?
Very Easy way, go to App.xaml.cs and coding like below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | private void Application_Startup(object sender, StartupEventArgs e) { Process thisProc = Process.GetCurrentProcess(); if (Process.GetProcessesByName(thisProc.ProcessName).Length > 1) { MessageBox.Show("Application running"); Application.Current.Shutdown(); return; } var wLogin = new LoginWindow(); if (wLogin.ShowDialog() == true) { var wMain = new Main(); wMain.WindowState = WindowState.Maximized; wMain.Show(); } else { Application.Current.Shutdown(); } } |
Views (444)

Hi,
The solution you suggested is working for me. Thank you for this.
Cheers,
Santhosh