Why does a Thread (which I set IsBackgroundthread to True) is not running with the threadpool Threads ?
/*1*/ volatile bool r = false;
/*2*/ var g= new Thread(() => r=Thread.CurrentThread.IsThreadPoolThread );
/*3*/ g.IsBackground = true;
/*4*/ g.Start();
/*5*/ g.Join();
/*6*/ Console.WriteLine(r); //false
While this code (obviously) does run at a threadpool thread ?
Task.Factory.StartNew(()=>Console.Write(Thread.CurrentThread.IsThreadPoolThread)); //true
Console.ReadLine();
p.s. (I know that Task are (by default)run at a background threads and they run in a threadpool , but my question is about a similar situation where I set a thread to run at background).)
The ThreadPool is a pool of dedicated threads managed by the runtime.
User-created background threads are not part of the threadpool.
In other words, all thread-pool threads are background threads, but not all background threads are thread-pool threads.
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