AcManager.Tools.Starters.BaseStarter.WaitUntilGameAsync C# (CSharp) Method

WaitUntilGameAsync() public method

public WaitUntilGameAsync ( CancellationToken cancellation ) : Task
cancellation System.Threading.CancellationToken
return Task
        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;
                }
            }
        }