2

I tested different projects with this simple code : ( 2010 ,4.5.1)

bool a, b;
new Thread(() => { a = Thread.CurrentThread.IsThreadPoolThread; }).Start();
Task.Factory.StartNew(() => { b = Thread.CurrentThread.IsThreadPoolThread; });

I wanted to see which projects uses threadpool thread and which doesn't : ( as a default(!) invocation without LongOperation switch)

So :

WPF enter image description here

— Doesn't use threadpool threads.

Console enter image description here

— Doesn't use threadpool threads.

Winform enter image description here

— Doesn't use threadpool threads.

Asp.net

enter image description here

Does use for Task

It's actually the last place I'd think about - that asp.net uses threadpool thread for task. ( each threadpool thread is important for serving other requests)

Question

Why does Only asp.net uses threadpool thread when creating/running new task ? ( Also , with the fact that Tp threads are precious resource)

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

1 Answers1

3

They all use threadpool threads, you are not waiting long enough for the code to run. You need to do a .Join() on your thread version and a .Wait() on the task version to wait for the code to complete before you check the result of a and b.

bool a, b;
new Thread(() => { a = Thread.CurrentThread.IsThreadPoolThread; }).Start().Join();
Task.Factory.StartNew(() => { b = Thread.CurrentThread.IsThreadPoolThread; }).Wait();
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431