mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Improved Task usage
This commit is contained in:
parent
cbe2751db7
commit
4e753ae718
10 changed files with 30 additions and 39 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ namespace MapControl
|
|||
topImage.Source = image;
|
||||
SetBoundingBox(topImage, boundingBox);
|
||||
|
||||
await OpacityHelper.SwapOpacities(topImage, bottomImage);
|
||||
await OpacityHelper.SwapOpacitiesAsync(topImage, bottomImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
/// </summary>
|
||||
public Task LoadTilesAsync(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress)
|
||||
public async Task LoadTilesAsync(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> 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<byte>(), // 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue