다른 스레드에서 콘솔 프로세스를 실행하는 양식 응용 프로그램을 만들고 있습니다. 기본적으로 응용 프로그램이 종료 된 후 단추를 차단 해제해야합니다. 이벤트 처리기를 만들기 전에 완료 후 프로세스가 막 중단되었지만 지금은 이벤트 후 응용 프로그램 자체가 종료됩니다. 이벤트 핸들러 자체의 I는 Thread.IsBackground 속성 작업을 시도응용 프로그램 종료 프로세스 종료 이벤트
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();
}
,하지만 아무것도 여기
변경하지 않은 :
다음 프로세스 실행을 만들기위한 코드입니다void p_Exited(object sender, EventArgs e)//Process on exit or disposed will make button1 avalable
{
button1.Enabled = true;
}
추가 아이디어가있는 이유는 무엇입니까?
p.EnableRaisingEvents = true;
은 이제 프로세스가 아니라 죽었습니까? 여기
@HansPassant 고맙습니다! – TheBW