我有两个类,来自 WPF 的主类和在“PersistDataToTable.Persist”内称为“PersistDataToTable”的子类我有一个循环,我想将该循环增量传递回主 WPF 类以显示在进度条中。我有一个后台工作线程运行命中循环的方法,我只是不知道如何从后台工作线程将数据返回给 ReportProgress 方法。
private void PersistDataToDb(object sender, RoutedEventArgs e)
{
worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += delegate(object o, DoWorkEventArgs args)
{
PersistDataToTable persistData = new PersistDataToTable();
persistData.Persist(seriesId);
worker.ReportProgress(loop incrament from persist()??);
};
worker.ProgressChanged += delegate(object o, ProgressChangedEventArgs args)
{
int percentage = args.ProgressPercentage;
progressBar.Value = percentage;
};
worker.RunWorkerAsync();
}