从 C# 表单中,我正在运行一个进程,其启动信息类似于将控制台输出重定向到单独程序中的文本框,并且C# 在运行时获取进程输出,该进程运行正确,但输出需要很长时间才能出现在DataReceived 事件中。
我希望在流程生成后立即看到文本;根据流程标准输出无法捕获?(第一条评论)我需要等到 2 到 4 kb 的缓冲区填满后才能触发事件。
根据要求,这是代码:
void pcs_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Data))
textBox1.BeginInvoke((Action)delegate { textBox1.AppendText(text + "\n"); });
}
private void LER_Go_Click(object sender, EventArgs e)
{
// variables LiDARExtRep contains the full path to an executable file
// that runs in DOS and produces verbose output.
// LER_Path.Text is the parameter passed to LiDARExtRep (only one arg for this example)
ProcessStartInfo pStartInfo …Run Code Online (Sandbox Code Playgroud)