We are running several background process in wpf application. We want to close all background process when we close the application.Currently when we close the application then application does not close completely and exe is showing in the task manager and visual studio raising the error. How to fix this in wpf?
Asked
Active
Viewed 768 times
-1
-
Set `Thread.IsBackground` for every single one, or keep track of them and cancel them, what have you tried? [mcve]? – Manfred Radlwimmer Nov 04 '16 at 11:21
-
we running several process and we have no idea which process have been completed and which are not. But we want to close all the process with application. – Matthew Siddle Nov 04 '16 at 11:40
-
Possible duplicate of [WPF Application still runs in background after closing](http://stackoverflow.com/questions/3543704/wpf-application-still-runs-in-background-after-closing) – Alexandr Sargsyan Nov 04 '16 at 11:49
-
If you don't know which process has completed, you might want to get to that first. If it's an actual process, you can track that with the `Exited` event or by calling `WaitForExit` or the `HasExited` property. If it's just a thread in your main process, You can use `Join`, `Interrupt`, `Abort`, etc.. – Manfred Radlwimmer Nov 04 '16 at 11:50
-
@AlexandrSargsyan, this is not a duplicate. OP's asking about a _different_ process. – Drew Noakes Nov 05 '16 at 23:50
1 Answers
0
Look into Job Objects. They allow creation of a group for processes in which, if the parent exits, all children are killed as well.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684161(v=vs.85).aspx

Drew Noakes
- 300,895
- 165
- 679
- 742