Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.86/5 (3 votes)
See more:
Hello,
I am designing wpf application... My problem is that on window closing i want to kill the task in the task manager ... Can anyone please help me out.
Posted
Updated 13-Nov-21 18:04pm
v2
Comments
Ziee-M 6-Nov-13 1:42am    
When closing your form, the application should handle closing process in the task Manager, if it dosent, then you have some ressources used that blocks the application from terminating.
You should dispose all disposable ressources and terminates your application threads in the form closing event!
jing567 6-Nov-13 1:44am    
how to dispose all that threads yar... I am new to this please provide me if you have any sample snippet
Ziee-M 6-Nov-13 2:01am    
Share your code or some of it, otherwise no one can help you!

Just Place ane event in the xaml code

Closing="Window_Closing"



Then write a event handler for that closing event in .cs page

Code:

C#
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
       {
           Application.Current.Shutdown();

       }
 
Share this answer
 
Have you tried using process.Kill() to kill process in task manager


C#
using System.Diagnostics;
 foreach (Process proc in Process.GetProcessesByName("OUTLOOK"))
            {
                proc.Kill();
            }


Hope it helps you.
 
Share this answer
 
Comments
jing567 6-Nov-13 4:59am    
Hello Keerth,
Can you help me that how to get the exact name of my application ... Dont laugh at my question.. I am placing my app name but i am unable to get the process
keerth516 6-Nov-13 6:23am    
ha ha ha...okay normally WPF app running in task manager will appear as appName.vshot.exe

and am not sure what is your purpose of doing it.
jing567 6-Nov-13 7:13am    
Hi Keerth,
My requirement is that whenever I close my window application , the service that is associated to that application should be killed... thats what my requirement....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900