Solved

VS2008 Thread to update label

Posted on 2009-05-08
5
240 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

806 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