yakovd33
yakovd33

Reputation: 55

Lambda thread with IsBackground

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

Answers (3)

Reza Aghaei
Reza Aghaei

Reputation: 125277

You can use:

new Thread(() =>
{
    //
})
{ IsBackground = true }.Start();

Upvotes: 1

Zer0
Zer0

Reputation: 7354

 new Thread(() =>
 { 
      // Do whatever
 })
 { IsBackground = true }.Start();

Upvotes: 3

Mario Vernari
Mario Vernari

Reputation: 7306

Your first solution should work:

Thread t = new Thread(() => {
    ...
});
t.IsBackground = true;
t.Start();

More info here.

Upvotes: 0

Related Questions