36 lines
883 B
C#
36 lines
883 B
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Media;
|
|
|
|
namespace OrderSupportTicket.Services;
|
|
|
|
/// <summary>
|
|
/// 商品缩略图加载器,限制并发下载数量,避免工单列表同时发起大量请求。
|
|
/// </summary>
|
|
internal static class ProductImageLoader
|
|
{
|
|
private static readonly SemaphoreSlim Gate = new SemaphoreSlim(4, 4);
|
|
|
|
public static async Task<ImageSource> LoadAsync(string url)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
return null;
|
|
|
|
await Gate.WaitAsync().ConfigureAwait(false);
|
|
try
|
|
{
|
|
return await Task.Run(
|
|
() => AllBase.ImageBuild.LoadBitmipImageFromUrl(url.Trim()))
|
|
.ConfigureAwait(false);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
finally
|
|
{
|
|
Gate.Release();
|
|
}
|
|
}
|
|
}
|