Is there a way to reuse threads used in consecuent calls of Parallel.ForEach
loop? I am tring to do because I understand that thread creation can be costly.
Thats what i would like to do:
var collection = CreateMyCollection()
var pool = CreateThreadPool()
for(int i =0 ; i<1000 ; i++)
Parallel.ForEach(pool, collection, (element) => Calculate(element, i))
Is it possible?
Note: I cannot parallize the external loop instead (hard dependancy between 'i's')
Parallel.ForEach is part of TPL. By default TaskSceduler, responsible for queuing work items onto threads, will use ThreadPool.