nmap의 표준 출력을 WPF 윈도우 응용 프로그램 (텍스트 상자)에 넣으려고합니다. Dispatcher.Invoke를 사용하려고하는데 nmap 프로세스가 시작될 때 모든 것이 멈추게됩니다. 콘솔 응용 프로그램 (Invoke 없음)에서이 작업을 시도해 본 결과, 모든 것이 제대로 작동 했으므로 Invoke 메서드에 문제가 있다고 생각합니다. Nmap 자체가 작동하고 끝내지 만 내 창에는 응답이 없습니다.다른 프로세스에서 UI를 업데이트 할 수 없습니다.
Process nmap = new Process();
nmap.StartInfo.FileName = Properties.Settings.Default.NmapResidentialPath;
nmap.StartInfo.Arguments = arguments.ToString();
nmap.StartInfo.UseShellExecute = false;
nmap.StartInfo.RedirectStandardOutput = true;
nmap.OutputDataReceived += new DataReceivedEventHandler(nmap_OutputDataReceived);
nmap.Start();
nmap.BeginOutputReadLine();
nmap.WaitForExit();
nmap.Close();
그리고 이벤트 핸들러 방법 :
void nmap_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => nmapOutput.Text += "\n" + e.Data));
}
}
nmap 프로세스가 끝난 직후에 프로세스를 시작하는 BeginInvoke 창이 있는데, 여전히 내 창에 출력이 없습니다. nmapOutput은 UI 스레드에 의해 생성됩니다. – anusiak
백그라운드 스레드에서 nmap 프로세스를 시작 하시겠습니까? nmap.WaitForExit()이 아닌 경우 UI 스레드를 차단하고 창을 고정시킵니다. –