vb.net中长时间运行进程的实时重定向和解析
此代码执行“handbrakecli”(命令行应用程序),并将输出放入字符串中:vb.net中长时间运行进程的实时重定向和解析,vb.net,parsing,process,external-application,Vb.net,Parsing,Process,External Application,此代码执行“handbrakecli”(命令行应用程序),并将输出放入字符串中: Dim p As Process = New Process p.StartInfo.FileName = "handbrakecli" p.StartInfo.Arguments = "-i [source] -o [destination]" p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.S
Dim p As Process = New Process
p.StartInfo.FileName = "handbrakecli"
p.StartInfo.Arguments = "-i [source] -o [destination]"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.Start
Dim output As String = p.StandardOutput.ReadToEnd
p.WaitForExit
问题是,这可能需要20分钟才能完成,在此期间不会向用户报告任何内容。一旦完成,他们将看到应用程序的所有输出,其中包括进度细节。不是很有用
因此,我试图找到一个样本,展示以下方面的最佳方式:
有人有推荐的代码段吗?StandardOutput属性的类型为StreamReader,它有ReadToEnd以外的方法。 这将是更多的代码,但是如果您使用Read方法,您可以做其他事情,比如为用户提供取消或报告某种类型进度的机会 链接到带有代码示例的Read方法: 编辑: Process类还有一个BeginOutputReadLine方法,它是一个带有回调的异步方法调用