-1

重複の可能性:
バックグラウンドワーカーが進行状況を報告しない

WPF でバックグラウンド ワーカーを使用しています。問題は、進捗状況が報告されていないことです。タスクが完了すると、ProgressBar が更新されるだけです。バックグラウンドタスクの実行中に定期的に更新したい。これが私のサンプルコードです。

  bworker_doWork(...)
    {
       BindData();//this is database operation which binds data to datagrid.
    }

    bWorker_ProgressChanged(...)
    {
       progressBar.Value=e.ProgressPercentage;//it doesnt update this value
    }

    bWorker_RunWorkerCompleted(..)
    {
       progressBar.Value=100;//max value. control comes here and updates the progress to max value.
    }
4

1 に答える 1

-1

ProgressPercentage をどこかに設定していますか? (提出したコードからはわかりません)

あなたが見逃していると思うのは、コードで ReportProgress を呼び出さなければならないということです。そのような:

myBackgroundWorker.ReportProgress((int)percent, null);

あなたのコードでは、次のようになると思います。

bworker_doWork(...)
{
   BindData();//this is database operation which binds data to datagrid.
   bworker.ReportProgress((int)percent);
}

bWorker_ProgressChanged(...)
{
   progressBar.Value=e.ProgressPercentage;//it doesnt update this value
}

bWorker_RunWorkerCompleted(..)
{
   progressBar.Value=100;//max value. control comes here and updates the progress to max value.
}
于 2012-10-11T07:04:35.663 に答える