diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 5c9d86ce5..3fe6a8c74 100755 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -23,6 +23,7 @@ */ using HtmlAgilityPack; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Globalization; @@ -37,7 +38,9 @@ namespace ArchiSteamFarm { private readonly ManualResetEvent FarmResetEvent = new ManualResetEvent(false); private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1); + private readonly Bot Bot; + private readonly Timer Timer; internal readonly ConcurrentDictionary GamesToFarm = new ConcurrentDictionary(); internal readonly List CurrentGamesFarming = new List(); @@ -46,6 +49,13 @@ namespace ArchiSteamFarm { internal CardsFarmer(Bot bot) { Bot = bot; + + Timer = new Timer( + async e => await CheckGamesForFarming().ConfigureAwait(false), + null, + TimeSpan.FromMinutes(15), // Delay + TimeSpan.FromMinutes(15) // Period + ); } internal static List GetGamesToFarmSolo(ConcurrentDictionary gamesToFarm) { @@ -76,7 +86,7 @@ namespace ArchiSteamFarm { } internal bool FarmMultiple() { - if (GamesToFarm == null || GamesToFarm.Count == 0) { + if (GamesToFarm.Count == 0) { return true; } @@ -288,6 +298,14 @@ namespace ArchiSteamFarm { Semaphore.Release(); } + private async Task CheckGamesForFarming() { + if (NowFarming || CurrentGamesFarming.Count > 0 || GamesToFarm.Count > 0) { + return; + } + + await StartFarming().ConfigureAwait(false); + } + private async Task ShouldFarm(ulong appID) { bool? result = null; HtmlDocument gamePageDocument = await Bot.ArchiWebHandler.GetGameCardsPage(appID).ConfigureAwait(false);