Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I kill a function running as a thread (.Net)

I've just started with C#. I'm running an object's function as a thread (new Thread(myFunc).Start()).

Does the thread kill itself when the function is finished or must I manually get rid of it? If I must, what is the best way to do it (I may not know when it finishes etc)?

Thanx!

like image 552
MeLight Avatar asked Sep 08 '26 14:09

MeLight


1 Answers

Yes the thread will exit when the function returns. If it is a long-running task and you want to be sure it has finished before the program exits, you can use Thread.Join which will block the main thread until the other thread completes.

like image 96
Lee Avatar answered Sep 10 '26 03:09

Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!