I’m calling a class function in a thread function. I’m using invoke method to send a value to a progressbar in the main form and I don’t know how to do that in an other class function called by the thread function.
My goal is to send a value to a progressbar to the main form from the thread function and even from the function called by the thread function.
My code:
‘ Invoke sub
Public Sub UpdPgEvent(ByVal value As Integer)
Me.pgFindEvent.Value = value
End Sub
' Sub started by the thread
Private Sub ThreadTaskMonitor()
Dim ConnectURL As String
' Delegate progressbar
Dim DelegPgEvent As DelegueUpgPbEvent = New DelegueUpgPbEvent(AddressOf UpdPgEvent)
' This invoke works great
Me.Invoke(DelegPgEvent, 10)
ConnectURL = "..."
Me.Invoke(DelegPgEvent, 20)
' What I want is to send state value from this call to the main form progressbar
urlr.JsonGetEvents(ConnectURL)
Dim table_res As List(Of monitor_table) = urlr.ConstructDataMonitor()
Me.Invoke(DelegPgEvent, 80)
Me.MonitorBindingSource.DataSource = table_res
Me.Invoke(DelegPgEvent, 90)
mon.dbMonitor.DataSource = Me.MonitorBindingSource
Me.Invoke(DelegPgEvent, 0)
End Sub
Thank for your help
You Need to pass your main form to the class.
Here is a sample.