I have write a simple code just to test about BeginInvoke and EndInvoke methods but i don't get anything.
The form has 2 buttons and 2 labels .. if you press the button1 label1 gets increase and so on .
here what i have do so far

Public Class Form1

    Dim mySimpleClass As New simpleClass
    Public Delegate Sub doCounDelegate(ByVal yourLabel As Label)
    Dim myDoCount As New doCounDelegate(AddressOf mySimpleClass.doCount)
    Dim iasync1 As IAsyncResult
    Dim iasync2 As IAsyncResult

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        iasync1 = myDoCount.BeginInvoke(Label1, Nothing, Nothing)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        iasync2 = myDoCount.BeginInvoke(Label2, Nothing, Nothing)
        'myDoCount = EndInvoke(iasync2)
    End Sub

End Class

Public Class simpleClass
    Public Sub doCount(ByVal yourLabel As Label)
        For i = 0 To 50
            yourLabel.Text = i
    End Sub
End Class

If i comment the line yourLabel.Text=i i think it works fine i can see the value on the console
any suggestion ??

adatapost Thanks it works but the result isn't predict.

it behaves like a synchronously call why?
and i want to make it more flexible for example to be able to count twice at the same time if user click button1 and 2 accordingly.

This article has been dead for over six months. Start a new discussion instead.