本文整理汇总了C#中System.Diagnostics.Process.WaitForProcessStop方法的典型用法代码示例。如果您正苦于以下问题:C# Process.WaitForProcessStop方法的具体用法?C# Process.WaitForProcessStop怎么用?C# Process.WaitForProcessStop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.WaitForProcessStop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessIt
private void ProcessIt(string command, int? timeoutMilliseconds)
{
using (var ffmpegProcess = new Process())
{
ffmpegProcess.StartInfo = new ProcessStartInfo
{
FileName = ResourceManagement.CommandConfiguration.FFmpegPath,
WorkingDirectory = ResourceManagement.CommandConfiguration.TempPath,
Arguments = command.Trim(),
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardError = true,
};
Log.Debug($"ffmpeg.exe MonoRuntime={ResourceManagement.IsMonoRuntime()} Args={ffmpegProcess.StartInfo.Arguments}");
var stdErrorReader = StandardErrorAsyncStreamReader.AttachReader(ffmpegProcess);
ffmpegProcess.Start();
//workaround for a bug in the mono process when attempting to read async from console output events
// - link http://mono.1490590.n4.nabble.com/System-Diagnostic-Process-and-event-handlers-td3246096.html
// we will wait a total of 10 seconds for the process to start, if nothing has happened in that time then we will
// return a failure for the event.
ffmpegProcess.WaitForProcessStart();
stdErrorReader.Listen();
var processStopped = ffmpegProcess.WaitForProcessStop(timeoutMilliseconds);
if (!processStopped)
{
throw new FFmpegTimeoutException(ffmpegProcess.StartInfo.Arguments);
}
stdErrorReader.Stop();
StdOut = stdErrorReader.ToString();
Log.Debug($"ffmpeg.exe MonoRuntime={ResourceManagement.IsMonoRuntime()} Output={StdOut}.");
var exitCode = ffmpegProcess.ExitCode;
if (exitCode != 0)
{
throw new FFmpegProcessingException(exitCode, StdOut);
}
}
}