有没有比StandardOutput.ReadToEnd更有效的(时间复杂性)方法

本文关键字:时间复杂性 方法 有效 StandardOutput ReadToEnd 有没有 | 更新日期: 2023-09-27 18:29:57

我想让我的项目更快。我使用了Stopwatch类并计算了这些代码块之间的时间。大部分时间都花在string output = p.StandardOutput.ReadToEnd();行。有什么建议可以用这个代码来代替吗?

Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = DBUpdater_Adresi;         
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
p.StartInfo = startInfo;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

有没有比StandardOutput.ReadToEnd更有效的(时间复杂性)方法

大部分时间花在这一行上的原因是它等待您启动的程序的整个执行。它不需要时间,因为它效率低下,它需要时间,是因为它在等待另一个过程。

最后一行等待进程退出,但从输出流关闭到进程结束的时间非常短。