public async Task WaitUntilGameAsync(CancellationToken cancellation) {
if (GameProcess != null) return;
Logging.Warning("WaitUntilGameAsync(): first stage");
var nothing = 0;
for (var i = 0; i < 999; i++) {
GameProcess = Process.GetProcessesByName(AcsName.ApartFromLast(".exe", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (GameProcess != null) break;
if (IsAny()) {
nothing = 0;
} else if (++nothing > 50) {
Logging.Warning("WaitUntilGameAsync(): looks like the game is dead");
break;
}
await Task.Delay(1000, cancellation);
if (cancellation.IsCancellationRequested) {
Logging.Warning("WaitUntilGameAsync(): cancelled");
return;
}
}
}