Events and Background worker

  • Thread starter Thread starter sjoshi
  • Start date Start date
S

sjoshi

I have a class that sends event notifications during a time consuming
operation. In the UIclass for the form, I have subscribed to that event
to paint the progress bar in this

_backupMgr_PercentCompleted(object sender, JobCompletedEventArgs e)
{

}

If I now use a background worker now in the UI, how would I handle the
paint in do_work method ?

thanks
Sunit
 
Can you be more specific?

You can't perform any interaction with a form within the DoWork event
handler of BackgroundWorker as it's in a different thread than the form. The
progress and completed events of the BackgroundWorker can interact directly
with the form as they are guaranteed to execute on the thread that
instantiated the BackgroundWorker object (assumes the same thread that
instantiated the Form object).

If you're doing custom painting that has to be done in the OnPaint method or
in a Paint event handler.
 
Peter said:
Can you be more specific?

You can't perform any interaction with a form within the DoWork event
handler of BackgroundWorker as it's in a different thread than the form. The
progress and completed events of the BackgroundWorker can interact directly
with the form as they are guaranteed to execute on the thread that
instantiated the BackgroundWorker object (assumes the same thread that
instantiated the Form object).

If you're doing custom painting that has to be done in the OnPaint method or
in a Paint event handler.

Thanks...I understand that. The thing I'm confused about is how to
communicate information from the event that I have subscribed to of the
_backupMgr class, to the progress event of the BackgroundWorker class.

Sunit
 
Back
Top