Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VS2008 Thread to update label

Posted on 2009-05-08
5
Medium Priority
?
250 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

824 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