【发布时间】:2012-01-04 12:41:06
【问题描述】:
我正在制作表单应用程序,它也在不同的线程上运行控制台进程。基本上我需要在应用程序退出后取消阻止按钮。在我制作事件处理程序之前,完成后的进程刚刚停止,但现在,在事件发生后应用程序本身被杀死。
这是使进程运行的代码:
public void CallConsole()//This Calls the console application
{
Thread.CurrentThread.IsBackground = true;
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = filename;
if (checkBox1.Checked)
p.StartInfo.CreateNoWindow = true;
p.EnableRaisingEvents = true;
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.Exited += new EventHandler(p_Exited);
p.Disposed += new EventHandler(p_Exited);
p.Start();
p.BeginErrorReadLine();
p.BeginOutputReadLine();
}
我尝试使用 Thread.IsBackground 属性,但这并没有改变任何东西
这是事件处理程序本身:
void p_Exited(object sender, EventArgs e)//Process on exit or disposed will make button1 avalable
{
button1.Enabled = true;
}
添加后应用程序的任何想法
p.EnableRaisingEvents = true;
现在被杀死了,不仅仅是进程?
【问题讨论】:
标签: c# winforms events process