Skip to content

Commit

Permalink
Fix issue where pendingTasks collection is modified while enumerated
Browse files Browse the repository at this point in the history
  • Loading branch information
Molinet, Fabien committed Jun 10, 2016
1 parent 01de443 commit 394f3e9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/FFImageLoading.Common/Work/WorkScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void SetPauseWork(bool pauseWork)

lock (_pendingTasksLock)
{
foreach (var task in _pendingTasks)
foreach (var task in _pendingTasks.ToList()) // FMT: here we need a copy since cancelling will trigger them to be removed, hence collection is modified during enumeration
task.ImageLoadingTask.Cancel();

_pendingTasks.Clear();
Expand Down Expand Up @@ -203,7 +203,7 @@ private async Task LoadImageAsync(IImageLoaderTask task)
{
lock (_pendingTasksLock)
{
foreach (var pendingTask in _pendingTasks)
foreach (var pendingTask in _pendingTasks.ToList()) // FMT: here we need a copy since cancelling will trigger them to be removed, hence collection is modified during enumeration
{
if (pendingTask.ImageLoadingTask != null && pendingTask.ImageLoadingTask.UsesSameNativeControl(task))
pendingTask.ImageLoadingTask.CancelIfNeeded();
Expand Down

0 comments on commit 394f3e9

Please sign in to comment.