Creating graphics in background

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My application requires user interaction with a graphics interface that is
changing (data is being collected and plotted). Sometimes the graphics
updates are slow and the user is locked out until completion for tasks like
scaling and reading the cursor and all that.

I would like to do all of the drawing and associated calculations in a
background worker then have the updated information flash onto the form
holding the graphics forthwith.

Is there a "Best" strategy for doing this??
 
I don't have time for a full code sample, but here's a gentle nudge:

You're on the right track. Investigate the
System.ComponentModel.BackgroundWorker class (VB2005). The class runs
code on a seperate thread, while also presenting events that get
raised on the main WinForms thread. These events allow you to both
report progress and return a result when the second thread completes.

Along with the PercentComplete property, the ProgressChangedEventArgs
class has both a UserState (Object) property that you can use to pass
back the graphical data (bitmap, image, or some such) which represents
the current progress. This will allow you to hand back to the main
thread the current image you want displayed, while leaving the
application responsive.

Note: Make sure you set the WorkerReportsProgress property on the
BackgroundWorker to true.

Good Luck,

-Mark
 
Back
Top