XAML-Map-Control/MapControl/UWP/TileImageLoader.UWP.cs
2025-08-21 14:25:58 +02:00

37 lines
925 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Xaml.Media;
namespace MapControl
{
public partial class TileImageLoader
{
private static async Task LoadTileImage(Tile tile, Func<Task<ImageSource>> loadImageFunc)
{
var tcs = new TaskCompletionSource<object>();
async void LoadTileImage()
{
try
{
tile.SetImageSource(await loadImageFunc());
tcs.TrySetResult(null);
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
}
if (!await tile.Image.Dispatcher.TryRunAsync(CoreDispatcherPriority.Low, LoadTileImage))
{
tcs.TrySetCanceled();
}
await tcs.Task;
}
}
}