Saturday, December 14, 2013
Getting pretty baffled on your C# or vb.NET programs? Your program is in the process in task manager although all of the windows are already closed? I already made several "quite"-big projects in vb.NET and seriously, such problem is really a pain the arse. :) But now, I'm learning C# and currently developing my program called: "Employee Locator v2.0". Anyways, I would like to share this solution that I've recently found out. After an hour, I finally solved my problem haha!
By the way, this program opens first its splashscreen, which of course let the user be informed what is going on in the background. During such duration of splashing such splashscreen, the user can close the program instantly, just like in MS Office 2013. Now, as soon as the user clicks the X button, the program is supposed to be closed and cleared in the Task Manager.
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!
1. Go to App.xaml, set your shutdownmode: (note that my StartupUri is set to my SplashScreen)
2. In your MainWindow XAML, add this:
3. Finally, make a closing handle event in your MainWindow.xaml.cs
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
private void Window_Closed(object sender, EventArgs e)
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: