Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code
Private Sub bwrkMain_ProgressChanged(ByVal sender As System.Object, _
           ByVal e As System.ComponentModel.ProgressChangedEventArgs) _
           Handles bwrkMain.ProgressChanged

    Dim strStatus As String = e.UserState.ToString
    Debug.Print(strStatus)
    Try
        Me.tsslStatus.Text = "status changed"
        lblStatus.Text = strStatus
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation)
    End Try
End Sub



but the status text does not change, debug.print does print the message though.

i am calling the ReportProgress from another thread created by the backgroundworker thread.

is this the problem?

what could be causing this?

[edit]Inline code changed to code block - OriginalGriff[/edit]
Posted
Updated 19-Jun-11 0:18am
v2

1 solution

The problem is simple: you cannot access UI components except from the thread that created them - i.e. the UI thread.
When you try from another thread it doesn't work, and should throw an exception.

You need to PInvoke it:
Private Sub ShowProgress(text As String)
	If InvokeRequired Then
		Invoke(New MethodInvoker(Function() Do
			ShowProgress(text)
		End Function))
	Else
		Me.tsslStatus.Text = text
	End If
End Sub



"hell, am using .net 2.0, and this example doesn't work"

It's a bugger when that happens! :laugh:
Private Delegate Sub MyDelegate(text As String)
Private Sub ShowProgress(text As String)
	If InvokeRequired Then
		BeginInvoke(New MyDelegate(AddressOf ShowProgress), text)
	Else
		tsslStatus.Text = text
	End If
End Sub
 
Share this answer
 
v2
Comments
Simon_Whale 19-Jun-11 9:38am    
great answer +5
Cool Smith 19-Jun-11 10:25am    
hello, am using .net 2.0, and this example doesn't work
Cool Smith 19-Jun-11 11:08am    
it was a typo, i wanted to say "hello, am using .net 2.0, and this example doesn't work"
OriginalGriff 19-Jun-11 11:14am    
I guessed! :laugh:

BTW: for some reason comments aren't showing today - it's been reported, but it means this will only be visible in your email...
Sergey Alexandrovich Kryukov 19-Jun-11 23:06pm    
Agree, all correct, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900