日期:2014-05-18  浏览次数:20919 次

[150分]请问,外部程序的异常导致主程序暂停运行,如何处理!
程序流程是这样的

t = new Thread(new ThreadStart(Listener));
t.Start();



Listener中死循环监听广播UDP消息,当有消息到来时
ExeCommand(udpcmd)

这是ExeCommand的一个重载函数
public string ExeCommandArray(string[] commandTexts)
  {
  Process p = new Process();
  p.StartInfo.FileName = "cmd.exe";
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardInput = true;
  p.StartInfo.RedirectStandardOutput = true;
  p.StartInfo.RedirectStandardError = true;
  p.StartInfo.CreateNoWindow = true;
  string strOutput = null;
  try
  {
  p.Start();
  foreach (string item in commandTexts)
  {
  p.StandardInput.WriteLine(item);
  }
  p.StandardInput.WriteLine("exit");
  strOutput = p.StandardOutput.ReadToEnd();
  p.WaitForExit();
  p.Close();
  }
  catch (Exception e)
  {
  strOutput = e.Message;
  }
  return strOutput;
  }
----------------------------------------
现在当CMD运行一个外部EXE时,有时候这个EXE会报出异常,问是否调试,我的主程序也暂停在那里,不再接收消息,直到我点击“不调试”……

这样的问题怎么解决?

------解决方案--------------------
我顶!!!Mark!
------解决方案--------------------

------解决方案--------------------
没有研究过哦;

干什么不 开辟一个线程;
------解决方案--------------------
顶你个肺
------解决方案--------------------
本来就没什么人了...
------解决方案--------------------
顶下 沉默的神
------解决方案--------------------
再顶
------解决方案--------------------
委托,回调