473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Updating GUI elements from a worker thread

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(Im ageName)

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!

Aug 2 '06 #1
1 1916
solved.

FishingScout wrote:
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(Im ageName)

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!
Aug 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tobias | last post by:
Hi! I had Apache 2.0.47 and PHP 4.3.0 DEV running successfully on a W2k Server. For some reason, I couldn't get PHP to read XML-Attributes with the DOM XML -functions. So I thought, it would be...
1
by: Ron James | last post by:
I have a Form based dialog which kicks off a worker thread. The form has a progress bar, and a Cancel button. The Cancel button Aborts the thread, and when exiting, the thread attempts to Show a...
1
by: Joshua Russell | last post by:
Firstly my main method is like this: static void Main(string args) { // New Form Thread FormHandler myFormHandler = new FormHandler(); ThreadStart myThreadStart = new...
11
by: DW | last post by:
I've gotten this question a couple of times in interviews and I don't know what they are looking for: How do you update a control's property, such as a textbox.text property, from a thread, in...
13
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a...
10
by: Curious | last post by:
Hi, I have a thread running, and at a point in this thread I am calling a method to update GUI controls. From the net I have read that updating GUI controls from the worker thread is bad...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
1
by: sklett | last post by:
I have been doing research on updating the UI while doing time intensive processing. Basically, I have a click event in my Form that will call a member function on one of my business objects, that...
4
by: Edwin Velez | last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx The URL above gives sample code for use within a Console Application. What I would like to do is use this code within a Windows Form. That...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.