The thread created by the following is the foreground thread
Thread workingThread = new Thread(new ParameterizedThreadStart(DoJob));
Can I make the thread created background?
Yes, you can; System.Threading.Thread
has an IsBackground
property.
Gets or sets a value indicating whether or not a thread is a background thread.
Thread workingThread = new Thread(new ParameterizedThreadStart(DoJob))
{ IsBackground = true };
I know this is an older thread, but the most practical solution how create new Thread is this:
new Thread(() => NameOfYourMethod()) { IsBackground = true }.Start();
If you need to create paramerized Thread, just do simple modification:
new Thread(() => NameOfYourMethod(param1, param2...)) { IsBackground = true }.Start();
And that's all, I hope it helps someone :)
*Use this only if you don't need to store Treads for some reason.
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