【发布时间】:2013-12-18 14:57:49
【问题描述】:
我有一个调用 exe 文件的 C# 应用程序。下面是我用来调用进程的代码:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "ContasillabeGame";
proc.StartInfo.Arguments = numeroSillabe + " " + numeroToken;
proc.OutputDataReceived += new DataReceivedEventHandler(OutputToTextArea);
proc.Start();
// Start the asynchronous read of the sort output stream.
proc.WaitForExit();
这里是用于从进程中获取数据的方法。
private void OutputToTextArea(object sendingProcess, DataReceivedEventArgs outLine)
{
// Collect the sort command output.
if (!String.IsNullOrEmpty(outLine.Data))
{
System.Console.WriteLine(outLine.Data);
}
}
使用此代码,我启动了应用程序 ContasillabeGame,但该应用程序没有任何结果。为什么?对于从 ContasillabeGame 发送消息,我使用此代码
发送消息的示例代码:
System.Console.WriteLine("pippo");
【问题讨论】:
-
您已将
EnableRaisingEvents设置为 false,然后在从未引发事件时感到惊讶。这应该不足为奇。 -
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。