Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Extensions/ParallelForEachExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -76,11 +77,12 @@ public List<Exception> ReadExceptions()
_exceptionListLock.Enter(ref lockTaken);
try
{
return _exceptionList;
// Return a copy, so the list being returned will not be modified
// by tasks that are still running if the loop was canceled
return new List<Exception>(_exceptionList ?? Enumerable.Empty<Exception>());
}
finally
{
_exceptionList = null;
_exceptionListLock.Exit(useMemoryBarrier: false);
}
}
Expand Down