diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index b22dda8dc..a7beadffd 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -56,7 +56,6 @@ namespace ArchiSteamFarm { private static readonly SemaphoreSlim GiftsSemaphore = new SemaphoreSlim(1); private static readonly SemaphoreSlim LoginSemaphore = new SemaphoreSlim(1); - private static readonly SemaphoreSlim PICSSemaphore = new SemaphoreSlim(1); private static readonly SteamConfiguration SteamConfiguration = new SteamConfiguration(); internal readonly ArchiLogger ArchiLogger; @@ -84,6 +83,7 @@ namespace ArchiSteamFarm { private readonly Timer HeartBeatTimer; private readonly SemaphoreSlim InitializationSemaphore = new SemaphoreSlim(1); private readonly SemaphoreSlim LootingSemaphore = new SemaphoreSlim(1); + private readonly SemaphoreSlim PICSSemaphore = new SemaphoreSlim(1); private readonly Statistics Statistics; private readonly SteamApps SteamApps; private readonly SteamClient SteamClient; @@ -237,6 +237,8 @@ namespace ArchiSteamFarm { CardsFarmer.Dispose(); HeartBeatTimer.Dispose(); InitializationSemaphore.Dispose(); + LootingSemaphore.Dispose(); + PICSSemaphore.Dispose(); Trading.Dispose(); // Those are objects that might be null and the check should be in-place @@ -349,15 +351,20 @@ namespace ArchiSteamFarm { } } - await LimitPICSRequestsAsync().ConfigureAwait(false); - AsyncJobMultiple.ResultSet productInfoResultSet; + await PICSSemaphore.WaitAsync().ConfigureAwait(false); + try { productInfoResultSet = await SteamApps.PICSGetProductInfo(appID, null, false); } catch (Exception e) { ArchiLogger.LogGenericException(e); return (0, DateTime.MinValue); + } finally { + Task.Run(async () => { + await Task.Delay(PICSCooldownInMiliseconds).ConfigureAwait(false); + PICSSemaphore.Release(); + }).Forget(); } // ReSharper disable once LoopCanBePartlyConvertedToQuery - C# 7.0 out can't be used within LINQ query yet | https://github.com/dotnet/roslyn/issues/15619 @@ -454,15 +461,20 @@ namespace ArchiSteamFarm { } internal async Task>> GetAppIDsToPackageIDs(IEnumerable packageIDs) { - await LimitPICSRequestsAsync().ConfigureAwait(false); - AsyncJobMultiple.ResultSet productInfoResultSet; + await PICSSemaphore.WaitAsync().ConfigureAwait(false); + try { productInfoResultSet = await SteamApps.PICSGetProductInfo(Enumerable.Empty(), packageIDs); } catch (Exception e) { ArchiLogger.LogGenericException(e); return null; + } finally { + Task.Run(async () => { + await Task.Delay(PICSCooldownInMiliseconds).ConfigureAwait(false); + PICSSemaphore.Release(); + }).Forget(); } Dictionary> result = new Dictionary>(); @@ -1386,14 +1398,6 @@ namespace ArchiSteamFarm { }).Forget(); } - private static async Task LimitPICSRequestsAsync() { - await PICSSemaphore.WaitAsync().ConfigureAwait(false); - Task.Run(async () => { - await Task.Delay(PICSCooldownInMiliseconds).ConfigureAwait(false); - PICSSemaphore.Release(); - }).Forget(); - } - private async Task MarkInventoryIfNeeded() { if (!BotConfig.DismissInventoryNotifications) { return;