public async Task <CommandResult> RunAsync( IList <string> args, string workingDir, IDictionary <string, string?> additionalEnv, Action <string>?onStandardOutput = null, Action <string>?onStandardError = null, Action <EngineEvent>?onEngineEvent = null, CancellationToken cancellationToken = default) { if (onEngineEvent != null) { var commandName = SanitizeCommandName(args.FirstOrDefault()); using var eventLogFile = new EventLogFile(commandName); using var eventLogWatcher = new EventLogWatcher(eventLogFile.FilePath, onEngineEvent, cancellationToken); try { return(await RunAsyncInner(args, workingDir, additionalEnv, onStandardOutput, onStandardError, eventLogFile, cancellationToken)); } finally { await eventLogWatcher.Stop(); } } return(await RunAsyncInner(args, workingDir, additionalEnv, onStandardOutput, onStandardError, eventLogFile : null, cancellationToken)); }