示例#1
0
        /// <summary>
        /// Starts a bot with the provided file path.
        /// And it keeps restarting the bot if it closes.
        /// </summary>
        /// <param name="botFileName">The filepath of the bot that will be started.</param>
        private async Task StartBotAsync(string botFileName)
        {
            var botProcess = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    CreateNoWindow  = false,
                    WindowStyle     = ProcessWindowStyle.Minimized,
                    FileName        = botFileName,
                    UseShellExecute = true
                }
            };

            // Keep restating the bot if it closes.
            while (true)
            {
                if (_botReader.GetShouldRestartBot(botFileName))
                {
                    botProcess.Start();
                    _logger.Log($"{botFileName} opened.");
                    botProcess.WaitForExit();
                    _logger.Log($"{botFileName} closed.");
                }
                else
                {
                    await Task.Delay(TimeSpan.FromSeconds(1.5)).ConfigureAwait(false);
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }