Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to BackGroundWorker change label.text
Message
From
17/12/2010 04:58:09
 
 
To
16/12/2010 22:28:19
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01492852
Message ID:
01493045
Views:
49
You're existing code, even if working, is unneccessarily complex. Sorry, I should have paid more attention to the VB translation. IAC I tested the code below so it should work for you.
Also, if I understand correctly, you want to pass more information to the ProgressChanged callback. The second argument to ProgressChangedEventArgs is an object so you can, for example, pass more complex information using a custom class as shown below.
Imports System.ComponentModel

Public Class Form2

Public WithEvents bg As BackgroundWorker


Private Sub bg_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) _
Handles bg.DoWork
Dim bw As BackgroundWorker = TryCast(sender, BackgroundWorker)
Dim pi As New ProgressInfo()
System.Threading.Thread.Sleep(1000)
pi.Actionstring = "Update the masterfile"
pi.ActionNumber = 1
bw.ReportProgress(10, pi)
System.Threading.Thread.Sleep(1000)
pi.Actionstring = "Update the masterfile finish"
pi.ActionNumber = 2
bw.ReportProgress(20, pi)
'Etc
End Sub

Private Sub bg_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) _
Handles bg.ProgressChanged
Dim pi As ProgressInfo = DirectCast(e.UserState, ProgressInfo)
Label1.Text = pi.Actionstring
Label2.Text = pi.ActionNumber.ToString()
ProgressBar1.Value = e.ProgressPercentage
End Sub


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bg = New BackgroundWorker()
bg.WorkerReportsProgress = True
bg.RunWorkerAsync()
End Sub
End Class


Public Class ProgressInfo
Public Property Actionstring() As String
Get
Return m_actionstring
End Get
Set(ByVal value As String)
m_actionstring = value
End Set
End Property
Public Property ActionNumber() As Integer
Get
Return m_actionNumber
End Get
Set(ByVal value As Integer)
m_actionNumber = value
End Set
End Property
Private m_actionNumber As Integer

Private m_actionstring As String
End Class
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform