Reputation: 55
When creating a new thread the regular way I can set the IsBackground
like that
Thread t = new Thread(foo);
t.IsBackground = true;
t.Start();
But how can I do it when running a lambda thread?
new Thread(() => {
...
}).Start();
Upvotes: 1
Views: 303
Reputation: 125277
You can use:
new Thread(() =>
{
//
})
{ IsBackground = true }.Start();
Upvotes: 1
Reputation: 7354
new Thread(() =>
{
// Do whatever
})
{ IsBackground = true }.Start();
Upvotes: 3
Reputation: 7306
Your first solution should work:
Thread t = new Thread(() => {
...
});
t.IsBackground = true;
t.Start();
More info here.
Upvotes: 0