Solved

VS2008 Thread to update label

Posted on 2009-05-08
5
239 Views
Last Modified: 2012-08-13
Why does this not work?

    Private Sub UpdateLabel(ByVal [text] As String, ByVal lbl As Label)
        Try
            If lbl.InvokeRequired Then
                Dim d As New LabelCallBack(AddressOf UpdateLabel)
                Me.Invoke(d, New Object() {[text]})
            Else
                lbl.Text = [text]
            End If
        Catch ex As Exception

        End Try
    End Sub

If I specify the label name, everything is fine.
0
Comment
Question by:ddepuemd
  • 2
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 24335034
Your LabelCallBack is pointing to the same function, which has a signature of (String, Label). However, in your Invoke() method, you are only passing the string. Have you tried passing the label as well?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24335171
You need to use Delegates to upate UI controls.
Check some examples that Idle_Mind have posted using threads, backgroundworkers, etc.
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24295878.html 
0
 

Author Comment

by:ddepuemd
ID: 24335173
Do you mean like this:

   Private Sub UpdateLabel(ByVal [text] As String, ByVal lbl As Label)
        Try
            If lbl.InvokeRequired Then
                Dim d As New LabelCallBack(AddressOf UpdateLabel)
                Me.Invoke(d, New Object() {[text]}, lbl)
            Else
                lbl.Text = [text]
            End If
        Catch ex As Exception

        End Try
    End Sub

That doesn't work either, the label doesn't update...
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24335177
Opps! I read it wrong.
What you are trying to do ?
0
 

Author Comment

by:ddepuemd
ID: 24335238
You were right kaufmed, this does work!!  

Private Sub UpdateLabel(ByVal [text] As String, ByVal lbl As Label)
        Try
            If lbl.InvokeRequired Then
                Dim d As New LabelCallBack(AddressOf UpdateLabel)
                Me.Invoke(d, New Object() {[text], lbl})
            Else
                lbl.Text = [text]
            End If
        Catch ex As Exception

        End Try
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now