C#
2014.05.23 10:26
외부 프로세스를 실행할 때 그 프로세스가 종료할 때까지 다음 루틴을 타지 못하게 해야 할 때
다물칸 주소복사
조회 수 543 추천 수 0 댓글 0
구분 | 팁&트릭 |
---|---|
출처 | 내가작성 |
private void ProcRunProc(string fileName, string Args = "") { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = fileName; startInfo.Arguments = Args; startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.WorkingDirectory = gMain.g_CurPath; startInfo.RedirectStandardInput = true; Process Proc = new Process(); Proc.StartInfo = startInfo; Proc.Start(); Proc.WaitForExit(); }
gMain.g_CurPath = 현재 디렉토리입니다.
ShellExecute함수를 써서 외부 실행파일을 돌려도 되는데 이럴 경우 그 프로세스가 종료하기 전에 그냥 루틴이 이어집니다.
만약 종료하고 나서 진행되야 할 루틴일 경우 낭패이죠.
이럴 경우 위 함수로 실행 시 WaitforExit()구문에 의해 프로세스가 종료 될 때까지 빠져나오지 않습니다.