首页 > 解决方案 > 与 PowerShell 相比,进程运行速度非常慢

问题描述

我正在使用一个名为ffprobe.exe(FFmpeg 库的一部分)的小脚本从视频文件中读取元数据。

这是我的代码:

'Setup the process
Dim Proc As New Process()
With Proc.StartInfo
    .FileName = "C:\ffmpeg.exe"
    .UseShellExecute = False
    .CreateNoWindow = True
    .RedirectStandardOutput = True
    .RedirectStandardError = True
    .Arguments = "C:\testVideoFile.mp4"
End With

'Start the process and wait for it to exit
Proc.Start()

'Set the process to be high-priority
Proc.PriorityClass = ProcessPriorityClass.High

'Listen for process output
ProcessOutput = ""
AddHandler Proc.OutputDataReceived, AddressOf Proc_OutputDataReceived
AddHandler Proc.ErrorDataReceived, AddressOf Proc_OutputDataReceived
AddHandler Proc.Exited, AddressOf Proc_Exited
Proc.BeginOutputReadLine()
Proc.BeginErrorReadLine()
Proc.EnableRaisingEvents = True

'Wait for the process to exit
PSProc.WaitForExit()

这段代码工作得很好。问题是它的运行时间比在 PowerShell 中运行的时间要长。PowerShell 看似立即运行脚本,但在我的应用程序中,上面的代码需要 1 到 3 秒才能执行。

我知道这个问题被问了很多,但我真的找不到一个明确的答案来解释为什么需要这么长时间。

我做错了什么还是这就是它的方式?

标签: vb.netprocess

解决方案


推荐阅读