Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VS2008 Thread to update label

Posted on 2009-05-08
5
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

670 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