Updating GUI elements from a worker thread

F

FishingScout

Thanks for taking a look at this problem for me.

I am developing an applicaiton in VB.NET 2005

I have a legacy dll that performs a callback to my windows application.
The callback works great and I can update variables and call stored
procedures in my database. The callback can represent lots of
different activity, one activity is a disconnect notification from an
Ethernet device. I would like to processes the disconnect message and
have it display an icon on my GUI. I have tried a few things but I am
failing. One detail that might be worth mentioning is that I start a
thread
in the callback to handle the processing of the message because some
callback processing requires significant time and I need to allow the
dll
thread to continue.

( The class names have been changed for simplicity )

The scenario: I have a form called "Locker" and a class called
"Hardware" and a dll that can call a method from Hardware called
"Callback".

While in the Callback procedure I would like to execute the following
"UpdateStatus" procedure in the Locker form:

Public Sub UpdateStatus(ByVal ImageName As String)

Dim stream As IO.Stream =
Me.GetType().Assembly.GetManifestResourceStream(ImageName)

If Not stream Is Nothing Then
Dim image As System.Drawing.Image =
System.Drawing.Image.FromStream(stream)
RFIDReaderStatus.Image = image
End If

End Sub

Here is what I have tried but could easily have been making a mistake:

Invoke - I tried Me.Invoke but there was some runtime error about the
form not having been assigned a handle

RaiseEvent but the function was never actually executed.

Calling the method directly ( which I already know is wrong but what
the
heck... ). Calling the UpdateStatus method directly didn't bomb out
but it
didn't update the image either. If I call the UpdateStatus in the
on-click
callback for a button, then the update works great.

Any help is greatly appreciated.

Should I be using invoke?
Should I be raising an event and handling the event in the GUI?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top