When I create a task like
Task task = Task.Factory.StartNew(() => someMethod(args));
in C # 4.0+, how can I get a link to the thread of this task?
Is it possible that the task runs in the same thread that created the task, or spawns more than one thread?
Update:The reasons are as follows:
Is a task always created in a separate thread from the one in which the task was created?Is it one, zero or more than one thread?Is it running on the same kernel?It is important to know, because, for example, I can sleep in the main thread, thinking that I am freezing the background worker
Update:Useful answer:
, , ?
, , TPL , , , , ( ), . , ; , , TPL . , , . , ( ), , - , , .
, ?
. , , . , , , , . LongRunning, Task. TaskScheduler, , .
LongRunning
Task
TaskScheduler
?
, .
, , , , ,
. , , . : - , , , , .
:
System.Threading.Thread.CurrentThread
, , TPL , " " .
Task.Factory.StartNew() (. ). , , TaskScheduler ( TaskScheduler , ).
.Net 4 TaskScheduler ThreadPool (. ), , ThreadPool Thread , .
ThreadPool.
, , ThreadPool Thread,