473,699 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 Thread2StatusTe st()
StatusBoxConten ts = "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(ByVa l 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.Invok e(newDelegate(s In))

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.Invok eRequired 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(Addr essOf StatusAdd) ' Queue up
some work for lblStatus to run StatusAdd
'--or-- Dim newDelegate As UIDelegate = AddressOf StatusAdd

lblStatus.Invok e(newDelegate)
Else

If Strings.Len(Str ings.Trim(Statu sBoxContents)) = 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() & ") " & StatusBoxConten ts ' If
not, just put this text up for viewing and exit
Exit Sub
Else
lStatusQueue += 1
If Not (lblStatus.Text .EndsWith("(cli ck for more)")) Then
lblStatus.Text &= " (click for more)"
End If
If sStatusQueue Is Nothing Then
lArrayEntries = 0
Else
lArrayEntries = UBound(sStatusQ ueue)
End If
If lStatusQueue >= lArrayEntries Then ReDim Preserve
sStatusQueue(lS tatusQueue)
sStatusQueue(lS tatusQueue) = "(" & Now() & ") " &
StatusBoxConten ts
End If
End If
End Sub

Jun 27 '08 #1
1 947
"Armin Zingler" <az*******@free net.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
8193
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 party COM component that takes about 5 seconds to run one of its functions (Network IO bound call). Since I dont want my GUI to freeze
13
371
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 base class for the worker class, and made up some functions/delegates to handle the invoke stuff for the UI and that was fine for a prototype. I rewrote this chunk, broke things out into different classes - but the threading is still the same - and...
3
2382
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 things. The method I am writing queries a large dataset. As part of my feedback to the user, I am updating the status bar when the connection is made and the dataset is actually retrieved. The dataset retrieval method I have placed on a separate...
4
1206
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 control on my form. (Treeview). Is this possible and how do I do it? Here is a simplisitc overview of what I am doing...
7
1126
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 click events on the mainform remain in real time. Through a little experimentation it seems that I can only use 1 sub to update the form to avoid cross threading. So maybe have the timer fire the 3 requests and then when they are complete fire the...
4
2330
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 inside ASP.NET. my questions is: having a ASP.NET AJAX page and my gridView inside an atlas:UpdatePanel control how can I update the panel so it shows the datagrid with the results
5
10903
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 have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked a bunch of code will get executed. I would like to show a Progress Bar / form in modal/ShowDialog...
7
2374
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 finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
5
6929
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 sound. But my little app is a 'fake' app and is designed to look like another - hence this seeming crazy situation of needing to fake a progess bar. PROBLEM.
3
395
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 Thread(AddressOf ChildForm.UpdateRetrieveTimer) t.Start() <<Snip>> Here is the code for the thread:
0
8686
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.