2009-12-03 4 views
2

시간이 오래 걸리는 프로세스가 있으며 진행 상황을 보여주는 창이 필요합니다. 그러나 진행 상황을 표시하는 방법을 파악할 수는 없습니다.대화 상자에서 진행 상황을 표시합니다.

if (procced) 
{ 
    // the wpf windows : 
    myLectureFichierEnCour = new LectureFichierEnCour(_myTandemLTEclass); 
    myLectureFichierEnCour.Show(); 

    bgw = new BackgroundWorker(); 
    bgw.DoWork += startThreadProcessDataFromFileAndPutInDataSet; 
    bgw.RunWorkerCompleted += threadProcessDataFromFileAndPutInDataSetCompleted; 

    bgw.RunWorkerAsync(); 
} 

그리고 :

private void startThreadProcessDataFromFileAndPutInDataSet(object sender, DoWorkEventArgs e) 
{ 
    _myTandemLTEclass.processDataFromFileAndPutInDataSet(
     _strCompositeKey,_strHourToSecondConversion,_strDateField); 
} 

내가 진행의 힌트를 얻을 수 _myTandemLTEclass.processProgress를 호출 할 수 있습니다

여기에 코드입니다.

답변

6

ProgressChanged 이벤트를 처리하고 사용자 인터페이스의 진행률 막대를 업데이트해야합니다.

작업 (DoWork 이벤트 처리기)을 수행하는 실제 기능에서 완료된 작업의 양을 지정하는 인수를 사용하여 BackgroundWorker 인스턴스의 ReportProgress 메서드를 호출합니다.

BackgroundWorker example in MSDN Library은 작업을 수행하는 간단한 코드 스 니펫입니다.

+0

BackgroundWorker에에 true로 WorkerReportsProgress 속성을 설정하는 것을 잊지 마세요 – Dabblernl

1

backgroundWorker 스레드가 DoWork 메서드와 ProgressChanged을 처리해야합니다.

WorkerReportsProgress 플래그를 true (기본적으로 해제)로 설정해야합니다.

는 예제 코드를 참조하십시오

private void downloadButton_Click(object sender, EventArgs e) 
{ 
    // Start the download operation in the background. 
    this.backgroundWorker1.RunWorkerAsync(); 

    // Disable the button for the duration of the download. 
    this.downloadButton.Enabled = false; 

    // Once you have started the background thread you 
    // can exit the handler and the application will 
    // wait until the RunWorkerCompleted event is raised. 

    // Or if you want to do something else in the main thread, 
    // such as update a progress bar, you can do so in a loop 
    // while checking IsBusy to see if the background task is 
    // still running. 

    while (this.backgroundWorker1.IsBusy) 
    { 
     progressBar1.Increment(1); 
     // Keep UI messages moving, so the form remains 
     // responsive during the asynchronous operation. 
     Application.DoEvents(); 
    } 
} 
관련 문제