diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index d5918d3f..6e62253e 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -71,7 +71,6 @@ namespace MapControl public static int MaxLoadTasks { get; set; } = 4; private readonly Queue tileQueue = new Queue(); - private int tileCount; private int taskCount; /// @@ -94,8 +93,7 @@ namespace MapControl tileQueue.Enqueue(tile); } - tileCount = tileQueue.Count; - + var tileCount = tileQueue.Count; var maxTasks = Math.Min(tileCount, MaxLoadTasks); while (taskCount < maxTasks) @@ -103,7 +101,7 @@ namespace MapControl taskCount++; Logger?.LogDebug("Task count: {count}", taskCount); - _ = Task.Run(async () => await LoadTilesFromStack(tileSource, cacheName, progress).ConfigureAwait(false)); + _ = Task.Run(async () => await LoadTilesFromStack(tileSource, cacheName, tileCount, progress).ConfigureAwait(false)); } } } @@ -113,11 +111,10 @@ namespace MapControl lock (tileQueue) { tileQueue.Clear(); - tileCount = 0; } } - private async Task LoadTilesFromStack(TileSource tileSource, string cacheName, IProgress progress) + private async Task LoadTilesFromStack(TileSource tileSource, string cacheName, int tileCount, IProgress progress) { while (true) {