在对话框中显示进度

Jul*_*iel 2 c# wpf multithreading progress backgroundworker

我有一个需要很长时间的过程,我想要一个窗口来显示进度.但是,我无法想象如何显示进度.

这是代码:

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

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

    bgw.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud)

和:

private void startThreadProcessDataFromFileAndPutInDataSet(object sender, DoWorkEventArgs e)
{
    _myTandemLTEclass.processDataFromFileAndPutInDataSet(
        _strCompositeKey,_strHourToSecondConversion,_strDateField);
}
Run Code Online (Sandbox Code Playgroud)

我可以打电话_myTandemLTEclass.processProgress来获得进展的暗示.

Meh*_*ari 6

您应该处理该ProgressChanged事件并在那里更新用户界面中的进度条.

在执行工作的实际函数(DoWork事件处理程序)中,您将使用指定已完成任务量的参数调用实例的ReportProgress方法BackgroundWorker.

MSDN Library中BackgroundWorker示例是一个简单的代码片段,可以完成这项工作.