Is this possible?
What I want to do is have my doWork method instantiate another class and then call its start method. Then i would like to report progress from that class back to the ProgressChanged handler in the parent class. I’ve tried passing a reference to the BackgroundWorker but i get an error.
private void ComplianceWorker_DoWork(object sender, DoWorkEventArgs e)
{
ComplianceControlCenter CCC =
new ComplianceControlCenter(taskList.CheckedItems.OfType<string>().ToList(),
file_box.Text, &ComplianceWorker);
CCC.start();
}
EDIT:
There is only 1 background worker. I would like to pass it by reference to the constructor of ComplianceControlCenter so i can send progress updates to it from inside that class. The reasoning is the class do some fairly complicated work and i need to have a division. So again, i would like to pass the background worker from the doWork method to the CCC object so i can call ComplianceWorker.ReportProgress();
Error 1 Cannot take the address of, get the size of, or declare a pointer to a managed type (‘System.ComponentModel.BackgroundWorker’)
You could do that, although I don’t see what purpose it would serve for simple cases. Since you are already inside the business method of a
BackgroundWorkerthere’s no point in using yet more threads by creating anotherBackgroundWorkerand you could do the same work inline.If you still want to have a second
BackgroundWorker, you can propagate progress changed events from the second worker to the first by attaching a handler to the second worker’sProgressChangedevent. This handler would then raise theProgressChangedevent on the first worker, propagating the news.For example:
This code attaches an event handler to the “second” worker with
which assumes that
ComplianceControlCenterexposes its ownBackgroundWorkerdirectly. Since that may not be the case, you can turn the relationship around by passing a reference tothis.PropagateProgressChangedto the constructor instead and letting it attach the event handler for you.