Report Progress from a method being executed within a background worker.
-
Hi, I have just got the handle of using a background worker in order to mutithread my application. However from all the examples I've seen it appears that EVERYTHING invloved in the background worker thread must be within the DoWork event - not very object orientated! How do I call a method of another object WITHIN that separate thread and have the intricasies of such a method be reported back to the background worker? For example:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Assessment.Update()
}I would like Assessment.Update() to be able to ReportProgress back to backgroundWorker1 in addition to any ReportProgress which may happen after Assessment.Update() has completed. Many thanks
-
Hi, I have just got the handle of using a background worker in order to mutithread my application. However from all the examples I've seen it appears that EVERYTHING invloved in the background worker thread must be within the DoWork event - not very object orientated! How do I call a method of another object WITHIN that separate thread and have the intricasies of such a method be reported back to the background worker? For example:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Assessment.Update()
}I would like Assessment.Update() to be able to ReportProgress back to backgroundWorker1 in addition to any ReportProgress which may happen after Assessment.Update() has completed. Many thanks
eddy556 wrote:
it appears that EVERYTHING invloved in the background worker thread must be within the DoWork event
Yes - The thread executes for the duration of your DoWork delegate. You can call methods on objects just like you would anywhere else. As with all multithreading, if objects are used by multiple threads simultaneously then you may need to provide synchronization.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi, I have just got the handle of using a background worker in order to mutithread my application. However from all the examples I've seen it appears that EVERYTHING invloved in the background worker thread must be within the DoWork event - not very object orientated! How do I call a method of another object WITHIN that separate thread and have the intricasies of such a method be reported back to the background worker? For example:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Assessment.Update()
}I would like Assessment.Update() to be able to ReportProgress back to backgroundWorker1 in addition to any ReportProgress which may happen after Assessment.Update() has completed. Many thanks
... and you can pass the BGW to the methods you call, so they can call BGW.ReportProgress to report progress. Or you can organize a delegate. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Hi, I have just got the handle of using a background worker in order to mutithread my application. However from all the examples I've seen it appears that EVERYTHING invloved in the background worker thread must be within the DoWork event - not very object orientated! How do I call a method of another object WITHIN that separate thread and have the intricasies of such a method be reported back to the background worker? For example:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Assessment.Update()
}I would like Assessment.Update() to be able to ReportProgress back to backgroundWorker1 in addition to any ReportProgress which may happen after Assessment.Update() has completed. Many thanks
Maybe this can help http://ichramm.blogspot.com/2008/05/uso-de-la-clase-backgoundworker.html[^] Time ago I had to use events to send the progress o a threded app, if you have to call a method of another object and dont want to pass the worker as parameter, you may use them.
Saludos!! ____Juan