Added optional image request cancellation

This commit is contained in:
ClemensFischer 2025-08-20 16:44:48 +02:00
parent ebd90f5a45
commit 34fda668c9
6 changed files with 98 additions and 27 deletions

View file

@ -1,13 +1,14 @@
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Media;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MapControl
{
public partial class TileImageLoader
{
private static Task LoadTileImage(Tile tile, Func<Task<ImageSource>> loadImageFunc)
private static Task LoadTileImage(Tile tile, Func<Task<ImageSource>> loadImageFunc, CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource();
@ -19,7 +20,10 @@ namespace MapControl
tcs.TrySetResult(); // tcs.Task has completed when image is loaded
tile.SetImageSource(image);
if (!cancellationToken.IsCancellationRequested)
{
tile.SetImageSource(image);
}
}
catch (Exception ex)
{