How to kill your program's process in Task Manager (VB.NET/C#) ?
Also, if the main window is to be closed by the user, the program shouldn't be displaying in the Task Manager Processes.
So, after several steps and changing of codes, I finally got the answered. In order to be sure: I executed these two steps:
1. As I've said, if the x button in the splashscreen is clicked, the whole program is killed! --- CHECKED!
2. If the Main Window is closed (X button is clicked), the whole program should also be killed! --- CHECKED!
SOLUTION:
1. Go to App.xaml, set your shutdownmode: (note that my StartupUri is set to my SplashScreen)
ShutdownMode="OnLastWindowClose"
2. In your MainWindow XAML, add this:
Closing="Window_Closing" Closed="Window_Closed"
3. Finally, make a closing handle event in your MainWindow.xaml.cs
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
System.Environment.Exit(0);
}
private void Window_Closed(object sender, EventArgs e)
{
System.Environment.Exit(0);
}
There are lots of ways to solve this, I know :). In order to be sure and avoid more debugging, I just doubled my event handlers. The Window_Closing and the Window_Closed.
article by: Glenn Posadas
additional tags: WPF in C#.NET, how to handle closing events, how to close all the apps in C# and VB.NET, VB.NET/C# closing events, closing events in C# WPF, WPF C# close all process after closing windows, C# WPF SplashScreen problems.
Sharing is so Easy: |














