Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I do with a thread when it's done ? leave it or abort it?

I create normal threads in asp.net application. After the thread is done what should I do ? leave it (it will get back to thread pool) or abort it.

Thread thread = new Thread(new ThreadStart(work));
like image 231
Xaqron Avatar asked Nov 18 '25 22:11

Xaqron


2 Answers

Leave it. There is no sense in creating a pointless exception.

like image 86
AngryHacker Avatar answered Nov 21 '25 12:11

AngryHacker


Recall that the IDisposable interface exists specifically for the scenario where some shared resource needs to be released. (It has been applied in other contexts as well, of course; but that is the situation it was originally meant for.)

Now consider that the managed Thread class does not implement IDisposable and you might guess (correctly) that it does not require any specific cleanup beyond normal handling by the GC.

like image 28
Dan Tao Avatar answered Nov 21 '25 12:11

Dan Tao