/// <summary> /// Will run <see cref="ReadToEnd"/> asynchronly. /// </summary> /// <param name="writer">The target stream.</param> /// <param name="reader">The source stream.</param> public static void BeginReadToEnd(System.IO.TextWriter writer, System.IO.TextReader reader) { var f = new OutputForward() { Writer = writer, Reader = reader }; new MethodInvoker(f.ReadToEnd).BeginInvoke(null, null); }
/// <summary> /// Executes and calls cabwiz.exe using the specified inf file. /// </summary> /// <param name="informationFile">A absolute path to the .inf file which is to be used by cabwiz.exe</param> /// <returns>The cabwiz.exe exit code. 0 indicates success, a non-zero value indicates failure.</returns> public int Run(string informationFile) { if (this.IsRunning) { throw new InvalidOperationException("The application is already running."); } else { this.IsRunning = true; if (!System.IO.Directory.Exists(this.DestinationDirectory)) { System.IO.Directory.CreateDirectory(this.DestinationDirectory); } try { using (System.Diagnostics.Process p = new System.Diagnostics.Process()) { p.StartInfo.FileName = this.FileName; p.StartInfo.Arguments = this.GetArguments(informationFile); p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); if (this.StandardOutput != null) { OutputForward.BeginReadToEnd(this.StandardOutput, p.StandardOutput); } if (this.StandardError != null) { OutputForward.BeginReadToEnd(this.StandardError, p.StandardError); } while (!p.HasExited) { if (this.CancelRequested) { p.WaitForExit(500); if (!p.HasExited) { p.Kill(); } } else { System.Threading.Thread.Sleep(300); } } return(p.ExitCode); } } finally { this.IsRunning = false; } } }