Hi,
I am trying to understand how the callback mechanism works. My Callback
function looks like this -->
Public Sub RemoteCallBack(ByVal iar As IAsyncResult)
TextBox2.Text = TextBox2.Text + "In Callback..." + vbCrLf
Dim obj As DelSub = CType(iar.AsyncState, DelSub)
obj.EndInvoke(iar)
TextBox2.Text = TextBox2.Text + "Finished Callback..." + vbCrLf
End Sub
The calling function looks like this -->
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As New RemoteType.clsRemoteType
Dim del1 As New DelSub(AddressOf send)
Dim ar As IAsyncResult
'Asynchronous Invocation begins
Dim objAsyncCallBack As New AsyncCallback(AddressOf RemoteCallBack)
ar = del1.BeginInvoke("ABC", Me.TextBox1.Text, objAsyncCallBack, del1)
TextBox2.Text = TextBox2.Text + "Main Thread ..." + vbCrLf
End Sub
My questions are ->
1> Can we implement the callback without passing the del1 object in
begininvoke ? What exactly the AsyncState does ?
2> The object in the main thread that invokes the functions goes out of
scope when the button_click function exits. So, how does it work on the
callback ? Is a new instance created ?
Regards,
pSm