Control Shape Graphic Properties from Background Process

Ian W

Active member
Joined
Feb 11, 2010
Messages
31
Programming Experience
1-3
Hi,

I have got a couple of VB Powerpack Ovalshapes on my Form.

I use these for a quick indication if the networked device is online or offline.

I can't seem to control the Visible function (or any other function for that matter) one my Background Worker is running.

For my Textboxes I used a guide by jmcilhinney which worked great for them but there is no 'Invoke' property for graphics controls.

Current code to update simply reads

VB.NET:
Me.OfflineImg.Visible = False

When I try and update a property I get..

"Cross-thread operation not valid: Control 'ShapeContainer1' accessed from a thread other than the thread it was created on."

How can I update the propertys of this item?
 
You can use any control that belongs to the UI thread, including the form itself, to Invoke the call to that thread. The whole purpose is that the method is called in UI thread, not that a particular control marshals it there.

OvalShape is a Component, not a Control, that is why it has no Control.Invoke method. But if you read it's help pages you see that this component requires a ShapeContainer parent, which is a special control that host these shapes. This control is implicitly added and is available from the Parent property. So you can also use this to Invoke.

Why not use the ReportProgress/ProgressChanged functionality of BackgroundWorker to report UI updates? That's what it's there for.
 
Back
Top