My code:
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerSupportsCancellation = true;
worker.WorkerReportsProgress = true;
worker.ProgressChanged += new ProgressChangedEventHandler (worker_ProgressChanged);
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
ResourceConsumingFunction();
};
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
Finished(true);
};
worker.RunWorkerAsync();
I wish to report progress quite frequently but have no idea how to do this. I cant modify resourceConsumingFunction();
Any ideas?
As Øyvind Knobloch-Bråthen correctly points out – if you cant get info back from ResourceConsumingFunction about progress then you can’t report it.
You need some way to hook into ResourceConsumingFunction to measure its progress. Is it creating files, writing something to disk or altering accessable variables that you can measure/use as progress value without having access to the workings of the function?
If you can’t get an external handle on the progress of this function then your doomed.