private async Task <bool> Farm(ulong appID) { if (NowFarming) { AutoResetEvent.Set(); Thread.Sleep(1000); AutoResetEvent.Reset(); } 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); } if (AutoResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) { success = false; break; } keepFarming = await ShouldFarm(appID).ConfigureAwait(false); } Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID); Bot.PlayGame(0); NowFarming = false; return(success); }
private async Task <bool> Farm(ulong 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); } if (FarmResetEvent.WaitOne(1000 * 60 * StatusCheckSleep)) { success = false; break; } keepFarming = await ShouldFarm(appID).ConfigureAwait(false); } Bot.PlayGame(0); NowFarming = false; Logging.LogGenericInfo(Bot.BotName, "Stopped farming: " + appID); return(success); }