That is true. The thread pool is optimised for small units of work and you can interfere with other work by holding onto a thread pool thread.
My rule of thumb is if an operation can take more than a second, it should not be on a thread pool thread. That is probably quite long.
Although this is undocumented, if you start a Task
with TaskCreationOptions.LongRunning
then a new Thread will be started to run the Task.
For most IO tasks, there are asynchronous versions of the framework methods that you should really use. These make use of kernel functions and mean that you won't be blocking any thread.
As always, I recommend reading Joe Albahari's free ebook,
followed by Joe Duffy's Concurrent Programming on Windows. The later is 1000 pages long, but is full of useful details.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…