Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stopping and removing thread after completing of task in .net

I have developed one window application in C# where i am creating one thread to perform one schedule event. now this application will run the whole day and it will create one thread for each execution of each event. How to remove threads from memory after task assigned to that thread is completed. I dont want to restrict number of threads creation by using thread pool and assigning it a specific count for max thread.

like image 250
Denish Avatar asked Aug 01 '11 05:08

Denish


1 Answers

As soon as a thread finishes its execution, it will no longer consume memory and it will be targeted for the garbage collector to collect it. Thus, you don't need to worry about it. However if you are using Task, it is a good practice to Dispose it when it finishes its execution. The Task is IDisposable object.

like image 174
Jalal Said Avatar answered Oct 18 '22 23:10

Jalal Said