Hello

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)
        'myDoCount.EndInvoke(iasync1)
    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
            Threading.Thread.Sleep(100)
            Console.WriteLine(i)
            Form1.Refresh()
        Next
    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 ??

Use Label1.BeginInvoke.

Label1.BeginInvoke(myDoCount, Label2)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.