示例#1
0
        private async Task <int?> HandleDebugDirectiveAsync(CommandInput commandInput)
        {
            // Debug mode is enabled if it's allowed in the application and it was requested via corresponding directive
            var isDebugMode = _configuration.IsDebugModeAllowed && commandInput.IsDebugDirectiveSpecified();

            // If not in debug mode, pass execution to the next handler
            if (!isDebugMode)
            {
                return(null);
            }

            // Inform user which process they need to attach debugger to
            _console.WithForegroundColor(ConsoleColor.Green,
                                         () => _console.Output.WriteLine($"Attach debugger to PID {Process.GetCurrentProcess().Id} to continue."));

            // Wait until debugger is attached
            while (!Debugger.IsAttached)
            {
                await Task.Delay(100);
            }

            // Debug directive never short-circuits
            return(null);
        }