2013-06-12 2 views
1

백그라운드 작업자와 진행률 표시 줄의 구현을 찾고 있습니다. 내가 찾을 수있는 것은 Threading.Sleep()을 사용한 시뮬레이션입니다. 시뮬레이션을 실제 SQL 쿼리로 변경하면 샘플은 모두 작동하지만 작동하지 않습니다.BackgroundWorker 내의 SQL 쿼리

아래 코드에서 검색어를 어디에 삽입해야합니까? .NET - 2.0

void m_oWorker_DoWork(object sender, DoWorkEventArgs e) 
    { 
     // The sender is the BackgroundWorker object we need it to 
     // report progress and check for cancellation. 
     //NOTE : Never play with the UI thread here... 
     for (int i = 0; i < 100; i++) 
     { 
      Thread.Sleep(100); 

      // Periodically report progress to the main thread so that it can 
      // update the UI. In most cases you'll just need to send an 
      // integer that will update a ProgressBar      
      m_oWorker.ReportProgress(i); 
      // Periodically check if a cancellation request is pending. 
      // If the user clicks cancel the line 
      // m_AsyncWorker.CancelAsync(); if ran above. This 
      // sets the CancellationPending to true. 
      // You must check this flag in here and react to it. 
      // We react to it by setting e.Cancel to true and leaving 
      if (m_oWorker.CancellationPending) 
      { 
       // Set the e.Cancel flag so that the WorkerCompleted event 
       // knows that the process was cancelled. 
       e.Cancel = true; 
       m_oWorker.ReportProgress(0); 
       return; 
      } 
     } 

     //Report 100% completion on operation completed 
     m_oWorker.ReportProgress(100); 
    } 

답변

1

"쿼리"를 사용하면 수행 할 작업이 하나만있는 것처럼 들립니다. SQL 쿼리의 진행을 실제로 측정 할 방법이 없으므로 진행률 표시 줄이 까다로워집니다. 얼마나 더 오래 될지 말할 수 없습니다. 쿼리를 수행하는 동안 비표준 무한 스크롤링 중 표시기를 사용하려고 할 수 있습니다.

0

당신은 CancellationPending 확인 후,이 배경 노동자의 실제 작업입니다 모든 SQL 쿼리를 실행해야합니다.