mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Image loading with cancellation
This commit is contained in:
parent
545e49b306
commit
220597ab31
|
|
@ -171,8 +171,11 @@ namespace MapControl
|
|||
protected async Task UpdateImageAsync()
|
||||
{
|
||||
updateTimer.Stop();
|
||||
|
||||
cancellationTokenSource?.Cancel();
|
||||
|
||||
ClearValue(LoadingProgressProperty);
|
||||
|
||||
if (ParentMap != null && ParentMap.ActualWidth > 0d && ParentMap.ActualHeight > 0d)
|
||||
{
|
||||
var width = ParentMap.ActualWidth * RelativeImageSize;
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ namespace MapControl
|
|||
|
||||
private readonly Progress<double> loadingProgress;
|
||||
private readonly DispatcherTimer updateTimer;
|
||||
private ITileImageLoader tileImageLoader;
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private ITileImageLoader tileImageLoader;
|
||||
private MapBase parentMap;
|
||||
|
||||
protected MapTileLayerBase()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Collections.Concurrent;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#if WPF
|
||||
|
|
@ -102,10 +103,12 @@ namespace MapControl
|
|||
|
||||
progress?.Report((double)(tileCount - pendingTiles.Count) / tileCount);
|
||||
|
||||
var requestCancellationToken = RequestCancellationEnabled ? cancellationToken : CancellationToken.None;
|
||||
Logger?.LogTrace("[{thread}] Loading tile image {zoom}/{column}/{row}", Environment.CurrentManagedThreadId, tile.ZoomLevel, tile.Column, tile.Row);
|
||||
|
||||
try
|
||||
{
|
||||
var requestCancellationToken = RequestCancellationEnabled ? cancellationToken : CancellationToken.None;
|
||||
|
||||
await LoadTileImage(tile, tileSource, cacheName, requestCancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -18,15 +18,15 @@ namespace MapControl
|
|||
{
|
||||
var image = await loadImageFunc();
|
||||
|
||||
tcs.TrySetResult(null); // tcs.Task has completed when image is loaded
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
tile.IsPending = true;
|
||||
tcs.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.SetImageSource(image);
|
||||
tcs.TrySetResult(null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -37,7 +37,7 @@ namespace MapControl
|
|||
|
||||
if (!await tile.Image.Dispatcher.TryRunAsync(CoreDispatcherPriority.Low, LoadTileImage))
|
||||
{
|
||||
tcs.TrySetCanceled(cancellationToken);
|
||||
tcs.TrySetCanceled(CancellationToken.None);
|
||||
}
|
||||
|
||||
await tcs.Task;
|
||||
|
|
|
|||
|
|
@ -18,15 +18,15 @@ namespace MapControl
|
|||
{
|
||||
var image = await loadImageFunc();
|
||||
|
||||
tcs.TrySetResult(); // tcs.Task has completed when image is loaded
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
tile.IsPending = true;
|
||||
tcs.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
tile.SetImageSource(image);
|
||||
tcs.TrySetResult();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -37,7 +37,7 @@ namespace MapControl
|
|||
|
||||
if (!tile.Image.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, LoadTileImage))
|
||||
{
|
||||
tcs.TrySetCanceled(cancellationToken);
|
||||
tcs.TrySetCanceled(CancellationToken.None);
|
||||
}
|
||||
|
||||
return tcs.Task;
|
||||
|
|
|
|||
Loading…
Reference in a new issue