Solved

VS2008 Thread to update label

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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