gpt4 book ai didi

C# 进程 <实例>.StandardOutput InvalidOperationException "Cannot mix synchronous and asynchronous operation on process stream."

转载 作者:行者123 更新时间:2023-11-30 22:46:21 35 4
gpt4 key购买 nike

我试过了

        myProcess = new Process();

myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

myProcess.StartInfo.FileName = "Hello.exe";

myProcess.StartInfo.Arguments ="-say Hello";
myProcess.StartInfo.UseShellExecute = false;

myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.ErrorDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.EnableRaisingEvents = true;

myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.ErrorDialog = true;
myProcess.StartInfo.WorkingDirectory = "D:\\Program Files\\Hello";

myProcess.Start();

myProcess.BeginOutputReadLine();
myProcess.BeginErrorReadLine();

然后我收到这个错误.. alt text http://img188.imageshack.us/img188/3759/errorstack.jpg

我的流程需要很长时间才能完成,所以我需要在运行时显示进度。

最佳答案

您无需调用 ReadLine() ,读取的文本行是在 DataReceivedEventArgs 中传递给您的属性之一。对象。

关于C# 进程 <实例>.StandardOutput InvalidOperationException "Cannot mix synchronous and asynchronous operation on process stream.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2681066/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com