Thread myThread = new Thread(new ParameterizedThreadStart(threadFunction));
public void threadFunction() {
// Run a finite code
...
}
Question is: will myThread
get disposed once threadFunction()
is over?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With