Delegates Callback With Threading
Private Delegate Sub AddValueToList(Value As Integer)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Thrd As New Threading.Thread(AddressOf StartProcess)
Thrd.Start()
End Sub
Private Sub StartProcess()
Dim RP As New RunningProcess
Dim X As Boolean = RP.SomeLongRunningProcessWithCallBack(AddressOf GetCallBackDelegateValue)
End Sub
Private Sub GetCallBackDelegateValue(Value As Integer)
ListBox1.Invoke(New AddValueToList(AddressOf AddValueToListBoxControl), Value)
End Sub
Public Class RunningProcess
Public Delegate Sub CallBackDelegate(Value As Integer)
Public Function SomeLongRunningProcessWithCallBack(Current As CallBackDelegate)
For intloop As Integer = 0 To 10000
'Some Long Running Process. File Downloading, Email Sending Creating Files, Complex Database Operartion
Dim i As Integer
i = intloop * 110 + 10
Current(i)
Next
Return True
End Function
End Class
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Thrd As New Threading.Thread(AddressOf StartProcess)
Thrd.Start()
End Sub
Private Sub StartProcess()
Dim RP As New RunningProcess
Dim X As Boolean = RP.SomeLongRunningProcessWithCallBack(AddressOf GetCallBackDelegateValue)
End Sub
Private Sub GetCallBackDelegateValue(Value As Integer)
ListBox1.Invoke(New AddValueToList(AddressOf AddValueToListBoxControl), Value)
End Sub
Public Class RunningProcess
Public Delegate Sub CallBackDelegate(Value As Integer)
Public Function SomeLongRunningProcessWithCallBack(Current As CallBackDelegate)
For intloop As Integer = 0 To 10000
'Some Long Running Process. File Downloading, Email Sending Creating Files, Complex Database Operartion
Dim i As Integer
i = intloop * 110 + 10
Current(i)
Next
Return True
End Function
End Class
Comments
Post a Comment