In C#, I am considering creating an array of BackgroundWorkers to work on an time-intensive problem. Each thread could last minutes.
Apparently though, 'threadpool' threads (which is what the BackgroundWorker uses) are not ideally meant to last longer than half a second. I quote:
It is important that you use a thread pool thread only when the work it does is limited, ideally not taking more than half a second.
I'd like to know the reasoning behind this, and also ask what the consequences are if I were to go ahead regardless. Is this because it's slower compared to Thread/Task, or is it memory-related, or is it because it bogs the system down, or is it some other issue?
One further comment from that post:
"It is therefore best suited for short bursts for work, not anything where performance matters.".
From my experimentation, I have not found this to be the case. For my (embarrassingly-parallel) problem at least, on a quadcore system and testing multiple times, 4 BackgroundWorkers
results in no apparent performance degradation relative to using 4 Threads
instead (and either of those makes makes the program run almost 4x as fast as using just a single BackgroundWorker
or Thread
as expected).
As a BackgroundWorker is simpler to use, from my perspective, I see no issue with keeping with that. If I am mistaken, please convince me otherwise.