ReportProgress in backgroundWorker does not work until the operation completes
When I call employee.ReportProgress () on an event BackgroundWorker.DoWork
, it won't work and the event ProgressChanged
will only be raised at the end of the loop for
.
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string writePath = Path.Combine(bookPath, "bytes");
DataTable dt = new DataTable();
dt = Form1.book.Select("select * from book");
Directory.CreateDirectory(writePath);
foreach (DataRow dr in dt.Rows)
{
int pagenumber = Convert.ToInt32(dr["pageNumber"]);
string text = dr["text"].toString();
byte[] codes = tocode.convertTobyte(text.ToCharArray());
File.WriteAllBytes(Path.Combine(writePath, pagenumber.ToString()),codes);
backgroundWorker1.ReportProgress((pagenumber * 100) / dt.Rows.Count);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBarMain.Value = e.ProgressPercentage;
}
+3
source to share
No one has answered this question yet
See similar questions:
or similar: