Reputation: 25595
Thread myThread = new Thread(new ParameterizedThreadStart(threadFunction));
public void threadFunction() {
// Run a finite code
...
}
Question is: will myThread
get disposed once threadFunction()
is over?
Upvotes: 13
Views: 12506
Reputation: 12705
YES.. the thread will stop and will be disposed once the function returns..
to hold the thread you will have to do something like
while(true){}
Alternatively if you dont want your thread to be disposed because creating a new thread consumes resources
you should use a ThreadPool
there is a class with the same name in .Net.
so every time you need a thread it will be fetched from the thread pool and utilized
Upvotes: 2
Reputation: 839114
Threads don't need to be disposed. The Thread
class does not implement IDisposable
and it does not have a Dispose
method.
When your thread completes you don't need to do anything special to clean up.
Upvotes: 19