我正在从进程运行bat文件,并希望在Listview中添加标准输出,我在其中编写代码
public void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (!string.IsNullOrEmpty(outLine.Data))
{
Trace.WriteLine(outLine.Data);
WriteInListBox(outLine.Data.ToString());
}
}
public delegate void WriteHandler(string s);
private void WriteInListBox(string text)
{
if (this.logText.InvokeRequired)
{
this.Invoke(new WriteHandler(WriteInListBox), new Object[] { text });
}
else
{
this.logText.Items.Add(Environment.NewLine + text);
}
}
现在它第一次尝试在listview中写行,然后它永远不会出现在WriteInListBox函数中并挂起