Use static HttpClient instance for heavy load issue

This commit is contained in:
Jack251970 2025-01-06 21:30:28 +08:00
parent cc0fb66b22
commit bc84910e56

View file

@ -17,7 +17,9 @@ namespace Flow.Launcher.Plugin.PluginsManager
{
internal class PluginsManager
{
const string zip = "zip";
private static readonly HttpClient HttpClient = new();
private const string zip = "zip";
private PluginInitContext Context { get; set; }
@ -151,8 +153,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
if (File.Exists(filePath))
File.Delete(filePath);
using var httpClient = new HttpClient();
using var response = await httpClient.GetAsync(plugin.UrlDownload, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
using var response = await HttpClient.GetAsync(plugin.UrlDownload, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
@ -165,7 +166,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
{
if (prgBox != null)
{
httpClient.CancelPendingRequests();
HttpClient.CancelPendingRequests();
downloadCancelled = true;
prgBox = null;
}