ThreadPool may not be optimal for getting stuck in it right away. You can explore the upper limits of your possibilities and / or minimize your own.
In addition, there is a race condition that exists in your code if you do not expect re-checks. Call
this.validatingItems.Add(itemId);
should happen in the main thread (ValidateItem), and not in the thread pool thread (validation method). This call must have a line before the work item queue in the pool.
Worst error found without checking QueueUserWorkItem return. The lineup may fail, and why it does not throw an exception is a mystery to us all. If it returns false, you need to remove the element that has been added to the validatingItems list and handle the error (probably throw an exception).
TheSoftwareJedi
source share