mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
TileImageLoader
This commit is contained in:
parent
115525cbfc
commit
b3d147bf5e
|
|
@ -13,7 +13,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
var image = await loadImageFunc().ConfigureAwait(false);
|
var image = await loadImageFunc().ConfigureAwait(false);
|
||||||
|
|
||||||
await Dispatcher.UIThread.InvokeAsync(() => tile.SetImageSource(image));
|
_ = Dispatcher.UIThread.InvokeAsync(() => tile.SetImageSource(image)); // no need to await InvokeAsync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class TileImageLoader
|
public partial class TileImageLoader
|
||||||
{
|
{
|
||||||
private static Task<object> LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
|
private static async Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<object>();
|
var tcs = new TaskCompletionSource<object>();
|
||||||
|
|
||||||
|
|
@ -20,9 +20,10 @@ namespace MapControl
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var image = await loadImageFunc();
|
var image = await loadImageFunc();
|
||||||
|
|
||||||
|
tcs.TrySetResult(null); // tcs.Task has completed when image is loaded
|
||||||
|
|
||||||
tile.SetImageSource(image);
|
tile.SetImageSource(image);
|
||||||
tcs.TrySetResult(null);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -30,9 +31,12 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = tile.Image.Dispatcher.RunAsync(CoreDispatcherPriority.Low, LoadTileImage);
|
if (!await tile.Image.Dispatcher.TryRunAsync(CoreDispatcherPriority.Low, LoadTileImage))
|
||||||
|
{
|
||||||
|
tcs.TrySetCanceled();
|
||||||
|
}
|
||||||
|
|
||||||
return tcs.Task;
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
var image = await loadImageFunc().ConfigureAwait(false);
|
var image = await loadImageFunc().ConfigureAwait(false);
|
||||||
|
|
||||||
await tile.Image.Dispatcher.InvokeAsync(() => tile.SetImageSource(image));
|
_ = tile.Image.Dispatcher.InvokeAsync(() => tile.SetImageSource(image)); // no need to await InvokeAsync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,9 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
var image = await loadImageFunc();
|
var image = await loadImageFunc();
|
||||||
|
|
||||||
|
tcs.TrySetResult(); // tcs.Task has completed when image is loaded
|
||||||
|
|
||||||
tile.SetImageSource(image);
|
tile.SetImageSource(image);
|
||||||
tcs.TrySetResult();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue