以下的代码为new Process() 调用cmd命令,并将结果异步回显到Form的例子:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace CmdCallbackShow
{
// 1.定义委托
public delegate void DelReadStdOutput(string result);
public delegate void DelReadErrOutput(string result);
public partial class Form1 : Form
{
// 2.定义委托事件
public event DelReadStdOutput ReadStdOutput;
public event DelReadErrOutput ReadErrOutput;
public Form1()
{
InitializeComponent();

此博客展示了如何使用C#的Process类异步执行CMD命令,并将命令输出实时更新到UI(如TextBox)中,提供了一个在Windows应用程序中交互执行命令行操作的实例。
最低0.47元/天 解锁文章
1098

被折叠的 条评论
为什么被折叠?



