/// <summary> /// Asynchronously execute a command line tool in this window, showing progress /// and finally calling the specified delegate on completion from the main / UI thread. /// </summary> /// <param name="toolPath">Tool to execute.</param> /// <param name="arguments">String to pass to the tools' command line.</param> /// <param name="completionDelegate">Called when the tool completes.</param> /// <param name="workingDirectory">Directory to execute the tool from.</param> /// <param name="ioHandler">Allows a caller to provide interactive input and also handle /// both output and error streams from a single delegate.</param> /// <param name="maxProgressLines">Specifies the number of lines output by the /// command line that results in a 100% value on a progress bar.</param> /// <returns>Reference to the new window.</returns> public void RunAsync( string toolPath, string arguments, CommandLine.CompletionHandler completionDelegate, string workingDirectory = null, Dictionary <string, string> envVars = null, CommandLine.IOHandler ioHandler = null, int maxProgressLines = 0) { CommandLineDialog.ProgressReporter reporter = new CommandLineDialog.ProgressReporter(); reporter.maxProgressLines = maxProgressLines; // Call the reporter from the UI thread from this window. UpdateEvent += reporter.Update; // Connect the user's delegate to the reporter's completion method. reporter.Complete += completionDelegate; // Connect the caller's IoHandler delegate to the reporter. reporter.DataHandler += ioHandler; // Disconnect the reporter when the command completes. CommandLine.CompletionHandler reporterUpdateDisable = (CommandLine.Result unusedResult) => { this.UpdateEvent -= reporter.Update; }; reporter.Complete += reporterUpdateDisable; PlayServicesResolver.Log(String.Format( "Executing command: {0} {1}", toolPath, arguments), level: LogLevel.Verbose); CommandLine.RunAsync(toolPath, arguments, reporter.CommandLineToolCompletion, workingDirectory: workingDirectory, envVars: envVars, ioHandler: reporter.AggregateLine); }