Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make sure all threads are closed or forcibly close a thread?

I a WPF/C# application that has a psuedo-process of Click a button > Start a thread to take a picture from a web cam API > Instantiate the web cam API > API starts a callback thread > Picture is taken > API object is disposed

These steps generally work except for the last portion where the callback thread to the web cam API does not close out. So, in my Task Manager, I invariably end up with a "ghost" process, which shares the same name as my base WPF application. Also, making a second call to the same web cam API (to take a second picture) fails miserably.

So, I'm trying to find a way to make sure that all of my threads from my root application are forcibly closed out at all times. Is there a way to ensure that no threads are left over?

like image 296
Unknown Coder Avatar asked Dec 21 '22 12:12

Unknown Coder


1 Answers

If you set IsBackground to true on those threads they will be terminated at shutdown.

like image 162
H.B. Avatar answered Dec 24 '22 02:12

H.B.