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

Comments

Popular posts from this blog

Shared / Static Class in vb.net/C#

Xamarin Forms : PopUp Page with RG.Plugins.Popup

Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)