How do I redirect a console program's output to a text box in a thread safe way?

ぃ、小莉子 提交于 2019-12-02 22:59:43
proc.WaitForExit();

It is called deadlock. Your main thread is blocked, waiting for the process to exit. That stops it from taking care of essential duties. Like keeping the UI updated. And making sure that Control.Invoke() requests are dispatched. That stops the AppendText() method from completing. Which stops the process for exiting. Which stops your UI thread from ever getting past the WaitForExit() call. "Deadly embrace", aka deadlock.

You cannot block your main thread. Use the Process.Exited event instead.

try

out_txtbx.Invoke(new AppendTextDelegate(this.AppendText), text);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!