From fccd8da9f6816fb0ff7d52bf0a5eb16f9aa2c8d7 Mon Sep 17 00:00:00 2001 From: RMBGAME Date: Sun, 14 Aug 2022 15:30:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0asynclock=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20asf=E5=90=AF=E5=8A=A8=E6=97=B6=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E4=BB=A4=E7=89=8C=E8=BE=93=E5=85=A5=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchiSteamFarmServiceImpl.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs b/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs index 0d23e553a..a8506ff7c 100644 --- a/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/ArchiSteamFarmServiceImpl.cs @@ -8,6 +8,7 @@ using ArchiSteamFarm.Steam; using ArchiSteamFarm.Steam.Storage; using ArchiSteamFarm.Storage; using Microsoft.Extensions.Configuration; +using Nito.AsyncEx; using NLog; using ReactiveUI; using System.Application.UI; @@ -37,6 +38,8 @@ namespace System.Application.Services.Implementation public TaskCompletionSource? ReadLineTask { get; set; } + private readonly AsyncLock @lock = new AsyncLock(); + bool _IsReadPasswordLine; public bool IsReadPasswordLine @@ -69,17 +72,20 @@ namespace System.Application.Services.Implementation ArchiSteamFarm.NLog.Logging.GetUserInputFunc = async (bool isPassword) => { - ReadLineTask = new(TaskCreationOptions.AttachedToParent); - IsReadPasswordLine = isPassword; + using (await @lock.LockAsync()) + { + ReadLineTask = new(TaskCreationOptions.AttachedToParent); + IsReadPasswordLine = isPassword; #if NET6_0_OR_GREATER - var result = await ReadLineTask.Task.WaitAsync(TimeSpan.FromSeconds(60)); + var result = await ReadLineTask.Task.WaitAsync(TimeSpan.FromSeconds(60)); #else - var result = await ReadLineTask.Task; + var result = await ReadLineTask.Task; #endif - if (IsReadPasswordLine) - IsReadPasswordLine = false; - ReadLineTask = null; - return result; + if (IsReadPasswordLine) + IsReadPasswordLine = false; + ReadLineTask = null; + return result; + } }; await ReadEncryptionKeyAsync();