diff --git a/Caches/FileDbCache/FileDbCache.cs b/Caches/FileDbCache/FileDbCache.cs index 723f332c..5fa64e57 100644 --- a/Caches/FileDbCache/FileDbCache.cs +++ b/Caches/FileDbCache/FileDbCache.cs @@ -149,7 +149,6 @@ namespace MapControl.Caching public void Refresh(string key) { - CheckArgument(key); } public void Remove(string key) @@ -185,24 +184,28 @@ namespace MapControl.Caching public Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = default) { Set(key, value, options); + return Task.CompletedTask; } public Task RefreshAsync(string key, CancellationToken token = default) { Refresh(key); + return Task.CompletedTask; } public Task RemoveAsync(string key, CancellationToken token = default) { Remove(key); + return Task.CompletedTask; } public Task CleanAsync() { Clean(); + return Task.CompletedTask; } diff --git a/Caches/SQLiteCache/SQLiteCache.cs b/Caches/SQLiteCache/SQLiteCache.cs index 8adff944..e78f38f9 100644 --- a/Caches/SQLiteCache/SQLiteCache.cs +++ b/Caches/SQLiteCache/SQLiteCache.cs @@ -138,13 +138,10 @@ namespace MapControl.Caching public void Refresh(string key) { - CheckArgument(key); } public Task RefreshAsync(string key, CancellationToken token = default) { - CheckArgument(key); - return Task.CompletedTask; } diff --git a/MapControl/Avalonia/OpacityHelper.Avalonia.cs b/MapControl/Avalonia/OpacityHelper.Avalonia.cs index 6413cf4c..e9303a38 100644 --- a/MapControl/Avalonia/OpacityHelper.Avalonia.cs +++ b/MapControl/Avalonia/OpacityHelper.Avalonia.cs @@ -32,7 +32,7 @@ namespace MapControl return animation.RunAsync(element); } - public static async Task SwapOpacities(Control topElement, Control bottomElement) + public static async Task SwapOpacitiesAsync(Control topElement, Control bottomElement) { var animation = new Animation { diff --git a/MapControl/Shared/ImageFileCache.cs b/MapControl/Shared/ImageFileCache.cs index ff0b6aaa..cdebac45 100644 --- a/MapControl/Shared/ImageFileCache.cs +++ b/MapControl/Shared/ImageFileCache.cs @@ -230,7 +230,7 @@ namespace MapControl.Caching public Task CleanAsync() { - return Task.Factory.StartNew(Clean, TaskCreationOptions.LongRunning); + return Task.Run(Clean); } private string GetPath(string key) diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index 3be499ac..d32a5db6 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -244,7 +244,7 @@ namespace MapControl topImage.Source = image; SetBoundingBox(topImage, boundingBox); - await OpacityHelper.SwapOpacities(topImage, bottomImage); + await OpacityHelper.SwapOpacitiesAsync(topImage, bottomImage); } } } diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index ffa4710a..d6012b24 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -113,7 +113,7 @@ namespace MapControl return finalSize; } - protected override Task UpdateTileLayer(bool tileSourceChanged) + protected override async Task UpdateTileLayer(bool tileSourceChanged) { var updateTiles = false; @@ -142,10 +142,8 @@ namespace MapControl { UpdateTiles(); - return LoadTiles(Tiles, SourceName); + await LoadTiles(Tiles, SourceName); } - - return Task.CompletedTask; } protected override void SetRenderTransform() diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 81af077e..37c0d9a5 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -62,7 +62,7 @@ namespace MapControl /// If tileSource.UriFormat starts with "http" and cacheName is a non-empty string, /// tile images will be cached in the TileImageLoader's Cache - if that is not null. /// - public Task LoadTilesAsync(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress) + public async Task LoadTilesAsync(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress) { pendingTiles?.Clear(); @@ -102,35 +102,33 @@ namespace MapControl tasks[i] = Task.Run(LoadTilesFromQueueAsync); } - return Task.WhenAll(tasks); + await Task.WhenAll(tasks); } } - - return Task.CompletedTask; } - private static Task LoadTileAsync(Tile tile, TileSource tileSource, string cacheName) + private static async Task LoadTileAsync(Tile tile, TileSource tileSource, string cacheName) { try { if (string.IsNullOrEmpty(cacheName)) { - return LoadTileAsync(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)); + await LoadTileAsync(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)); } - - var uri = tileSource.GetUri(tile.Column, tile.Row, tile.ZoomLevel); - - if (uri != null) + else { - return LoadCachedTileAsync(tile, uri, cacheName); + var uri = tileSource.GetUri(tile.Column, tile.Row, tile.ZoomLevel); + + if (uri != null) + { + await LoadCachedTileAsync(tile, uri, cacheName); + } } } catch (Exception ex) { Debug.WriteLine($"TileImageLoader: {tile.ZoomLevel}/{tile.Column}/{tile.Row}: {ex.Message}"); } - - return Task.CompletedTask; } private static async Task LoadCachedTileAsync(Tile tile, Uri uri, string cacheName) @@ -178,7 +176,7 @@ namespace MapControl } } - private static Task WriteCacheAsync(string cacheKey, byte[] buffer, TimeSpan? expiration) + private static async Task WriteCacheAsync(string cacheKey, byte[] buffer, TimeSpan? expiration) { if (!expiration.HasValue) { @@ -191,15 +189,13 @@ namespace MapControl try { - return Cache.SetAsync(cacheKey, + await Cache.SetAsync(cacheKey, buffer ?? Array.Empty(), // cache even if null, when no tile available new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = expiration }); } catch (Exception ex) { Debug.WriteLine($"TileImageLoader.Cache.SetAsync: {cacheKey}: {ex.Message}"); - - return Task.CompletedTask; } } } diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 893023b7..effae479 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -91,7 +91,7 @@ namespace MapControl return finalSize; } - protected override Task UpdateTileLayer(bool tileSourceChanged) + protected override async Task UpdateTileLayer(bool tileSourceChanged) { // tileSourceChanged is ignored here because it is always false. @@ -100,15 +100,12 @@ namespace MapControl { Children.Clear(); - return LoadTiles(null, null); // stop TileImageLoader + await LoadTiles(null, null); // stop TileImageLoader } - - if (UpdateChildLayers(tileMatrixSet)) + else if (UpdateChildLayers(tileMatrixSet)) { - return LoadTiles(tileMatrixSet); + await LoadTiles(tileMatrixSet); } - - return Task.CompletedTask; } protected override void SetRenderTransform() diff --git a/MapControl/WPF/OpacityHelper.WPF.cs b/MapControl/WPF/OpacityHelper.WPF.cs index daaee8c1..ab83d009 100644 --- a/MapControl/WPF/OpacityHelper.WPF.cs +++ b/MapControl/WPF/OpacityHelper.WPF.cs @@ -11,7 +11,7 @@ namespace MapControl { public static class OpacityHelper { - public static async Task SwapOpacities(UIElement topElement, UIElement bottomElement) + public static Task SwapOpacitiesAsync(UIElement topElement, UIElement bottomElement) { topElement.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { @@ -26,7 +26,7 @@ namespace MapControl Duration = TimeSpan.Zero }); - await Task.CompletedTask; + return Task.CompletedTask; } } } diff --git a/MapControl/WinUI/OpacityHelper.WinUI.cs b/MapControl/WinUI/OpacityHelper.WinUI.cs index 56feaafd..985abf41 100644 --- a/MapControl/WinUI/OpacityHelper.WinUI.cs +++ b/MapControl/WinUI/OpacityHelper.WinUI.cs @@ -26,7 +26,7 @@ namespace MapControl storyboard.Begin(); } - public static async Task SwapOpacities(UIElement topElement, UIElement bottomElement) + public static Task SwapOpacitiesAsync(UIElement topElement, UIElement bottomElement) { BeginOpacityAnimation(topElement, new DoubleAnimation { @@ -41,7 +41,7 @@ namespace MapControl Duration = TimeSpan.Zero }); - await Task.CompletedTask; + return Task.CompletedTask; } } }