[C#]Windows Forms与其它命令行程序的交互

来源:互联网 发布:nginx.org set 编辑:程序博客网 时间:2024/06/07 01:43

有时我们需要调用命令行程序完成一些工作,需要重定向标准输入和输出,这个工作看似简单,实际上牵涉到好几个方面的问题。

首先,由于是外部程序,需要使用System.Diagnostics.Process来启动运行,并重定向其输入输出;

其次,对于输入输出的处理,应该是异步的,不能影响UI的刷新,需要把输出结果及时地显示出来,因此需要使用专门的System.Threading.Thread来处理输入输出,因此涉及到多线程的处理。

 

Reference:

[MSDN] Safe, Simple Multithreading in Windows Forms

[MSDN] Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads

[MSDN] Launching a process and displaying its standard output

 

 

原创粉丝点击