From 7c3f5beb3a9889f02e28550e8aff8a2f6e2d50cd Mon Sep 17 00:00:00 2001 From: JustArchi Date: Wed, 18 Nov 2015 14:12:29 +0100 Subject: [PATCH] Hopefully fix all farming deadlocks, thanks to @Ryzhehvost, closes #14 --- ArchiSteamFarm/CardsFarmer.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/CardsFarmer.cs b/ArchiSteamFarm/CardsFarmer.cs index 759a9d968..2342dae4e 100644 --- a/ArchiSteamFarm/CardsFarmer.cs +++ b/ArchiSteamFarm/CardsFarmer.cs @@ -105,17 +105,23 @@ namespace ArchiSteamFarm { } } + Logging.LogGenericInfo(Bot.BotName, "Farming in progress..."); + NowFarming = true; + Semaphore.Release(); + // Start farming while (appIDs.Count > 0) { - Logging.LogGenericInfo(Bot.BotName, "Farming in progress..."); uint appID = appIDs[0]; + Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID); if (await Farm(appID).ConfigureAwait(false)) { appIDs.Remove(appID); } else { + NowFarming = false; return; } } + NowFarming = false; Logging.LogGenericInfo(Bot.BotName, "Farming finished!"); await Bot.OnFarmingFinished().ConfigureAwait(false); } @@ -152,17 +158,12 @@ namespace ArchiSteamFarm { } private async Task Farm(ulong appID) { + Bot.PlayGame(appID); + bool success = true; bool? keepFarming = await ShouldFarm(appID).ConfigureAwait(false); while (keepFarming == null || keepFarming.Value) { - if (!NowFarming) { - NowFarming = true; - Logging.LogGenericInfo(Bot.BotName, "Now farming: " + appID); - Bot.PlayGame(appID); - Semaphore.Release(); // We're farming, allow other tasks to shut us down - } else { - Logging.LogGenericInfo(Bot.BotName, "Still farming: " + appID); - } + Logging.LogGenericInfo(Bot.BotName, "Still farming: " + appID); if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) { success = false; break; @@ -171,7 +172,6 @@ namespace ArchiSteamFarm { } Bot.PlayGame(0); - NowFarming = false; Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID); return success; }