If a Task is created using the LongRunning option are there any side effects as they do not use the ThreadPool
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
The
LongRunning
option is a hint to the scheduler which means it may choose to execute theTask
on a non-ThreadPool Thread (if it's the thread-pool backedDefaultScheduler
it most likely will). One side-effect of theLongRunning
option is that Task Inlining is disallowed for that Task. This means that if theLongRunning
Task creates other nested or child Tasks and callsWait
on any of those Tasks, they will always be executed on a different Thread rather than being inlined (i.e. run on the same Thread performing theWait
).In the context of other people's answers it's worth noting that creating a large number of Tasks that take a long time to complete without the
LongRunning
hint is still likely to cause an escalation in the number of Threads due to the Thread Injection algorithm that theDefaultScheduler
uses. The algorithm doesn't distinguish between Threads in the pool that are blocked and those that have been running a work item for a long time and in both cases can respond by injecting more Threads into the pool to try to increase work-throughput.Yes. Side effect is that: if you have a million tasks, you could potentially create a million threads.
Need to take into account that each thread will bring its memory overhead and context switching overhead. Memory overhead is not that small, we are talking a few MB here so even with thousands of items, you could run into trouble.
LongRunning tasks, indicates that the global and local queues will be bypassed, so as to prevent it from blocking the other threads coming after it in the local queue.
That means, if you have lot of these Long Running tasks, it could create more threads than normal.
You can see in the answers on this question some of the drawbacks:
http://social.msdn.microsoft.com/Forums/en/parallelextensions/thread/8304b44f-0480-488c-93a4-ec419327183b