www.flickr.com

How to kill your program's process in Task Manager (VB.NET/C#) ?

Saturday, December 14, 2013 Posted by Glenn

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!

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.

glenn von

Author: Glenn Posadas

20 year old 5th year Computer Engineering Student, a blogger, photographer, programmer, and an electronics hobbyist; a Christian who loves God very much..

Sharing is so Easy:
StumpleUpon DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google Twitter FaceBook

  1. iAn

    Wow! Huma-hardcore tutorials...

  2. hello ian! LONG TIME NO CHAT AH ^__^. visit ako sa blog mo wait...

  3. Admin, if not okay please remove!

    Our facebook group “selfless” is spending this month spreading awareness on prostate cancer & research with a custom t-shirt design. Purchase proceeds will go to cancer.org, as listed on the shirt and shirt design.

    www.teespring.com/prostate-cancer-research

    Thanks

  4. Great news with: http://www.vigattininsurance.com
    you can secure you life while having a car that you driving Auto insurance 35% OFF plus free Road sine assistance.

  5. Great news with: http://www.vigattininsurance.com
    you can secure you life while having a car that you driving Auto insurance 35% OFF plus free Road sine assistance.

Post a Comment

Drop a comment. Thank you guys!