2011-08-12 7 views
0

현재 많은 명령 줄 및 기타 외부 프로세스를 하나의 응용 프로그램으로 통합하는 간단한 프로그램을 작성하고 있습니다.외부 프로세스의 진행률 표시 줄

현재 시스템 정보 프로세스를 사용하여 시스템 정보를 가져 오는 문제에 직면하고 있습니다.

시스템 정보 프로세스를 호출하는 버튼을 성공적으로 코딩했으며 출력을 텍스트 필드로 리디렉션했습니다.

지금 시도하고있는 것은 시스템 정보를로드하는 데 잠시 시간이 걸리기 때문에 내 WPF 창의 아래쪽에 진행률 표시 줄이있는 것입니다.

외부 프로세스에서 정확한 지속 시간을 얻는 방법을 모르므로 마키 스타일을 사용하려고합니다.

다른 사이트와 마찬가지로 stackoverflow (Windows Forms ProgressBar: Easiest way to start/stop marquee?)에서 예제를 수행했지만 systeminfo가 실행되는 동안 진행률 막대가 스크롤되도록 코드를 넣을 위치를 결정할 수 없었습니다. 은 끝났어.

현재 코드 (progressbar1.Style = ProgressBarStyle.Marquee; 제외)는 다음과 같습니다.

코드를 넣을 위치 나 사용할 구문에 대한 제안은 크게 감사하겠습니다. 미리 감사드립니다. 당신이해야 할 일은

private void btnSystemInfo_Click(object sender, RoutedEventArgs e) 
     { 


      // Get system info 
      Process info = new Process(); 
      info.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
      info.StartInfo.FileName = "C:\\Windows\\system32\\systeminfo.exe"; 
      info.StartInfo.Arguments = "-S " + context; 
      info.StartInfo.UseShellExecute = false; 
      info.StartInfo.CreateNoWindow = true; 
      info.StartInfo.RedirectStandardOutput = true; 

      info.Start(); 

      string infoOutput = info.StandardOutput.ReadToEnd(); 
      info.WaitForExit(); 

      // Write to the txtInfo text box 
      txtInfo.Text = "System Info: " + infoOutput; 
      txtInfo.Foreground = Brushes.Black; 
      txtInfo.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; 

      // Switch to the info tab 
      tabControl.SelectedIndex = 3; 
     } 

답변

4

는 윤곽을 시작 BackgroundWorker 스레드에서 메인 UI 스레드에서 시스템 정보를 수집하는 코드를 이동합니다. 당신이 작업이 완료가의 BackgroundWorker 스레드에서 신호를 얻을되면 윤곽을 중지하고 동시에 실행하려는 여러 프로세스가있는 경우, 다음에 보일 것입니다

void ButtonClickEvent() 
{ 
    BackgroundWorker bg = new BackgroundWorker(); 
    bg.DoWork += new DoWorkEventHandler(MethodToGetInfo); 
    bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted); 
    //show marquee here 
    bg.RunWorkerAsync(); 
} 

void MethodToGetInfo(Object sender, DoWorkEventArgs args) 
{ 
    // find system info here 
} 

void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs args) 
{ 
    //this method will be called once background worker has completed it's task 
    //hide the marquee 
    //update the textbox 

    //NOTE that this is not a UI thread so you will need BeginInvoke to execute something in the UI thread 
} 
+0

하리스 하산 감사합니다! 이것은 내가 찾고 있었던 것이다! – PsiLentRain

0

텍스트 상자에 정보를 표시 작업 라이브러리. 시스템 리소스에 따라 작업을 병렬 또는 직렬로 실행할 수 있습니다. 완료된 작업을 추적하여 수행 된 작업의 %를 표시 할 수도 있습니다.