mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Update GroundOverlay.cs
This commit is contained in:
parent
f15dde792e
commit
d00b16fd78
|
|
@ -5,7 +5,6 @@ using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
#if WPF
|
#if WPF
|
||||||
|
|
@ -71,8 +70,6 @@ namespace MapControl
|
||||||
private static ILogger logger;
|
private static ILogger logger;
|
||||||
private static ILogger Logger => logger ?? (logger = ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>());
|
private static ILogger Logger => logger ?? (logger = ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>());
|
||||||
|
|
||||||
public static int MaxLoadTasks { get; set; } = 4;
|
|
||||||
|
|
||||||
public static readonly DependencyProperty SourcePathProperty =
|
public static readonly DependencyProperty SourcePathProperty =
|
||||||
DependencyPropertyHelper.Register<GroundOverlay, string>(nameof(SourcePath), null,
|
DependencyPropertyHelper.Register<GroundOverlay, string>(nameof(SourcePath), null,
|
||||||
async (groundOverlay, oldValue, newValue) => await groundOverlay.LoadAsync(newValue));
|
async (groundOverlay, oldValue, newValue) => await groundOverlay.LoadAsync(newValue));
|
||||||
|
|
@ -163,26 +160,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
var imageOverlays = ReadImageOverlays(document);
|
var imageOverlays = ReadImageOverlays(document);
|
||||||
|
|
||||||
using (var semaphore = new SemaphoreSlim(MaxLoadTasks))
|
await Task.WhenAll(imageOverlays.Select(loadFunc));
|
||||||
{
|
|
||||||
var tasks = imageOverlays.Select(
|
|
||||||
async imageOverlay =>
|
|
||||||
{
|
|
||||||
// Limit number of simultaneous calls of loadFunc (in UI thread).
|
|
||||||
//
|
|
||||||
await semaphore.WaitAsync();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await loadFunc(imageOverlay);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
semaphore.Release();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Task.WhenAll(tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
return imageOverlays;
|
return imageOverlays;
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +249,7 @@ namespace MapControl
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
return Task.Run(() => XDocument.Load(docStream, LoadOptions.None));
|
return Task.Run(() => XDocument.Load(docStream, LoadOptions.None));
|
||||||
#else
|
#else
|
||||||
return XDocument.LoadAsync(docStream, LoadOptions.None, CancellationToken.None);
|
return XDocument.LoadAsync(docStream, LoadOptions.None, System.Threading.CancellationToken.None);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue