473,395 Members | 1,464 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,395 software developers and data experts.

Can I do this (threading and UI control update)

I want to be able to call my thread safe routine in a more normal way
but I cannot figure out the syntax or even if there is any. I have
tried all variations I can think of.

What I would like to code is:

StatusAdd("Here is the text to display.")

But what I do now is:

Sub Thread2StatusTest()
StatusBoxContents = "Here is the text to display."
StatusAdd()
End Sub

The routine it calls is below. It sees if a delegate invoke is needed
and recalls itself on the control in the main thread. It works just
fine but I would like to be able to call with one statement with a
parameter of what to display rather than the clunky dual statements.

It is the invoke call where the parameter gets lost and I don't know how
to pass it otherwise.

If I put an input parm spec on StatusAdd such as:

Public StatusAdd(sIn as string)

Then I have to put in:

Delegate Sub UIDelegate(ByVal sIn As String)

And then I have a problem with a message saying that the expression does
not produce a value on the following:

lblStatus.Invoke(newDelegate(sIn))

Suggestions?

Mike

---------------------The routine with the delegate invoke---------------

Public Sub StatusAdd()

'This routine HAS to be in the form which owns the control which
will be shared with other threads for reading and writing.
'It CANNOT be in the module file (for some reason I am not sure of
at this time).

Dim lArrayEntries As Integer

If lblStatus.InvokeRequired Then ' If I am on a thread other than
the one which owns the lblStatus control...

'Update the status box by invoking a delegate with the UI control
Dim newDelegate As New UIDelegate(AddressOf StatusAdd) ' Queue up
some work for lblStatus to run StatusAdd
'--or-- Dim newDelegate As UIDelegate = AddressOf StatusAdd

lblStatus.Invoke(newDelegate)
Else

If Strings.Len(Strings.Trim(StatusBoxContents)) = 0 Then Exit Sub
' Don't queue up an empty string.

If lblStatus.Text = "" Then ' First, see if there is any text
in the box.
lblStatus.Text = "(" & Now() & ") " & StatusBoxContents ' If
not, just put this text up for viewing and exit
Exit Sub
Else
lStatusQueue += 1
If Not (lblStatus.Text.EndsWith("(click for more)")) Then
lblStatus.Text &= " (click for more)"
End If
If sStatusQueue Is Nothing Then
lArrayEntries = 0
Else
lArrayEntries = UBound(sStatusQueue)
End If
If lStatusQueue >= lArrayEntries Then ReDim Preserve
sStatusQueue(lStatusQueue)
sStatusQueue(lStatusQueue) = "(" & Now() & ") " &
StatusBoxContents
End If
End If
End Sub

Jun 27 '08 #1
1 932
"Armin Zingler" <az*******@freenet.deschrieb
and it works!
I mean it can be compiled. If I undestood you correctly, you have a
compile problem, not a runtime exception.
Armin

Jun 27 '08 #2

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

Similar topics

8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
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...
3
by: Elliot Rodriguez | last post by:
Hi: I am writing a WinForm app that contains a DataGrid control and a StatusBar control. My goal is to update the status bar using events from a separate class, as well as some other simple...
4
by: Roger | last post by:
I have a function that is currently wrapped up in a Class so I can pass a variable to it. This function is going to be threaded out and I would like the class function to be able to update a...
7
by: melton9 | last post by:
I have a web service that I believe needs to implement threading. I have a timer setup to fire 3 requests and have them do some calculations and send the info to the mainform. I also need the...
4
by: Bruno Alexandre | last post by:
Hi guys, I have this page that needs to be populated with 2 diferent web services, and each one takes more or less 10 seconds to finish populate his own part, so I move on to the multi threading...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
3
by: Bill Schanks | last post by:
I have a form that gets opened, and it a separate thread I want a timer at the bottom of the form to update while the datagridview is updating. In my main form I have this: Dim t As New...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.