Dinindu Perera Dinindu Perera - 1 year ago 85
C# Question

Background Worker won't report progress

I have a Backrgound Worker which won't report progress. I need to get an exact value, not a percentage. I'm not sure how to code the progress changed event. I have set the WorkReportsProgress property to true. I'm still relatively new to C# so excuse my poor knowledge.

private void BKGWork_DoWork(object sender, DoWorkEventArgs e)
BackgroundWorker worker = sender as BackgroundWorker;
for (int i = 1; i <= 20; i++)
//do work
private void BKGWork_ProgressChanged(object sender, ProgressChangedEventArgs e)
//not sure how to get the exact value of i and compare it to see which loop the background worker is in.

Answer Source

Use worker.ReportProgress(0,i); to pass your explicit value as a user state parameter. Use can access this in e.UserState casting it to an int

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download