Fix rare restart issue

This commit is contained in:
JustArchi
2016-03-22 08:53:55 +01:00
parent 7d3c05088a
commit 7276350f74
3 changed files with 16 additions and 6 deletions

View File

@@ -148,7 +148,7 @@ namespace ArchiSteamFarm {
bool? isLoggedIn = await IsLoggedIn().ConfigureAwait(false);
if (isLoggedIn.HasValue && !isLoggedIn.Value) {
Logging.LogGenericInfo("Reconnecting because our sessionID expired!", Bot.BotName);
Task.Run(async () => await Bot.Restart().ConfigureAwait(false)).Forget();
Task.Run(async () => await Bot.RestartIfRunning().ConfigureAwait(false)).Forget();
return true;
}

View File

@@ -303,7 +303,11 @@ namespace ArchiSteamFarm {
}
}
internal async Task Restart() {
internal async Task RestartIfRunning() {
if (!SteamClient.IsConnected) {
return;
}
await Stop().ConfigureAwait(false);
await Start().ConfigureAwait(false);
}
@@ -1563,7 +1567,7 @@ namespace ArchiSteamFarm {
}
if (!await ArchiWebHandler.Init(SteamClient, callback.WebAPIUserNonce, BotConfig.SteamParentalPIN).ConfigureAwait(false)) {
await Restart().ConfigureAwait(false);
await RestartIfRunning().ConfigureAwait(false);
return;
}

View File

@@ -42,7 +42,7 @@ namespace ArchiSteamFarm {
private readonly Bot Bot;
private readonly Timer Timer;
private bool ManualMode, NowFarming;
private volatile bool ManualMode, NowFarming;
internal CardsFarmer(Bot bot) {
if (bot == null) {
@@ -178,10 +178,16 @@ namespace ArchiSteamFarm {
Logging.LogGenericInfo("Sending signal to stop farming", Bot.BotName);
FarmResetEvent.Set();
for (byte i = 0; i < 5 && NowFarming; i++) {
Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName);
Logging.LogGenericInfo("Waiting for reaction...", Bot.BotName);
for (byte i = 0; i < Program.GlobalConfig.HttpTimeout && NowFarming; i++) {
await Utilities.SleepAsync(1000).ConfigureAwait(false);
}
if (NowFarming) {
Logging.LogGenericWarning("Timed out!", Bot.BotName);
}
FarmResetEvent.Reset();
Logging.LogGenericInfo("Farming stopped!", Bot.BotName);
Semaphore.Release();