Does the .net function Parallel.ForEach block the calling thread? My guess as to the behavior is one of these:
Number 1 is correct; Parallel.ForEach
does not return until the loop has completed. If you don't want that behavior, you can simply execute your loop as a Task
and run it on another thread.
Re your update, StartNew in a normal foreach() :
This may not be the most optimal for large collections, and you don't get a point to handle errors.
Your loggingServices probably doesn't hold thousands of items but the errorhandling remains a point .
Consider:
Task.Factory.StartNew(() =>
{
try
{
Parallel.ForEach(loggingServices, l => l.LogMessage(request));
}
catch(SomeException ex)
{
// at least try to log it ...
}
});