Reputation: 86185
The thread created by the following is the foreground thread
Thread workingThread = new Thread(new ParameterizedThreadStart(DoJob));
Can I make the thread created background?
Upvotes: 11
Views: 24118
Reputation: 171
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.
Upvotes: 16
Reputation: 113472
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 };
Upvotes: 19
Reputation: 5529
new Thread(new ParameterizedThreadStart(DoJob)) { IsBackground = true };
Should be IsBackground, not IsBackGround
Upvotes: 1