web| Asynchronous
A simple instance of asynchronous invocation about WebService
In any case, the caller's code is the same whether it is invoked asynchronously or synchronously, and the code of the callee is the same.
Now, let's take an example of an asynchronous call to a webservice.
This is a WebService
_
Public Function delcurtable (ByVal tbname as String) as Boolean
Try
Return True
Catch ex as Exception
Return False
End Try
End Function
I'm not going to explain this webservice method of synchronous invocation.
Asynchronous invocation:
Private A as Vbwebservice. Datamanage ' defines a WebService variable
Dim ar as IAsyncResult
Public Sub Callback1 (ByVal ar As IAsyncResult)
"No code can be written here.
' Here the code starts running after the caller has run
End Sub
#region "Call asynchronously"
Private Sub btnStart_Click ()
Dim cb As Asyncallback=new Asyncallback (address (ME.CALLBACK1))
Ar=a.begindelcurtable ("ZDF", Cb,a)
End Sub
Private Sub Btnend_click ()
If AR is Nothing Then
Exit Sub
End If
If Ar. IsCompleted Then
Dim m as Boolean=a.enddelcurtable (AR)
MessageBox.Show (m.tostring)
End If
End Sub
#end Region
Note: "Returns the result of an asynchronous call that can only be invoked once, and if you want to do it again, you must rerun the Begin method."
The above is the usage of vb.net, the following is the use of C #
Cwebservice.datamanage A;
System.IAsyncResult ar;
private void Form1_Load (object sender, System.EventArgs e)
{
A=new Cwebservice.datamanage ();
}
public void CallBack1 (System.IAsyncResult ar)
{
}
private void btnStart_Click (object sender, System.EventArgs e)
{
System.AsyncCallback cb=new AsyncCallback (this. CALLBACK1);
Ar=a.begindelcurtable ("Zhang", cb,a);
}
private void Btnend_click (object sender, System.EventArgs e)
{
if (ar==null)
{
MessageBox.Show ("null");
return;
}
if (AR. iscompleted)
{
BOOL M=a.enddelcurtable (AR);
MessageBox.Show (M.tostring ());
}
Else
{
MessageBox.Show ("for completion");
}
}