2013-08-09 2 views
1

OLE 데이터베이스를 DataGridView로로드하는 응용 프로그램을 작성하고 있습니다. 데이터베이스 파일이 로컬에 저장되어 있지만 응용 프로그램에서 데이터베이스를로드하는 데 시간이 걸리므로 "로드 중"커서 만 가져옵니다. 좀 더 싶습니다 : db가로드되는 동안 표시 할 진행률 표시 줄을 만들고 db가 완전히로드 될 때 숨기기를 원합니다.C#의 데이터베이스로드 진행률

Google에서 검색했지만 찾으려는 항목을 찾지 못했습니다. 내가 무엇을 할 수 있을지?

(I 비주얼 스튜디오에서 작업하기 때문에 데이터 세트에 대한 전체 코드가 자동으로 IDE에 의해 작성되어 있음을 명심하고) 당신은 아마 모두 넣어 ProgressBar의 와 함께 사용되는 경우 BackgroundWorker를 찾고 있습니다

답변

2

을 양식에 다음과 같은 코드를 사용합니다

public partial class Form1 : Form 
{ 
public Form1() 
{ 
    InitializeComponent(); 
    Shown += new EventHandler(Form1_Shown); 

    // To report progress from the background worker we need to set this property 
    backgroundWorker1.WorkerReportsProgress = true; 
    // This event will be raised on the worker thread when the worker starts 
    backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork); 
    // This event will be raised when we call ReportProgress 
    backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged); 
} 
void Form1_Shown(object sender, EventArgs e) 
{ 
    // Start the background worker 
    backgroundWorker1.RunWorkerAsync(); 
} 
// On worker thread so do our thing! 
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 
{ 
    // Your background task goes here 
    for (int i = 0; i <= 100; i++) 
    { 
     // Report progress to 'UI' thread 
     backgroundWorker1.ReportProgress(i); 
     // Simulate long task 
     System.Threading.Thread.Sleep(100); 
    } 
} 
// Back on the 'UI' thread so we can update the progress bar 
void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) 
{ 
    // The progress percentage is a property of e 
    progressBar1.Value = e.ProgressPercentage; 
} 

}

이 그것을 사용하는 방법의 예에 불과합니다. 다음을 수정해야합니다.

backgroundWorker1.ReportProgress(i); 

실제로 OLE 데이터베이스와 관련된 진행 상황을보고합니다.