Simple instance of asynchronous call on WebService

zhaozj2021-02-16  82

Regarding the asynchronous call simple instance of WebService, in any case, the code of the called party is the same as the asynchronous call or synchronous call,

Below, we call a WebService as an example as an example as an asynchronous. This is a WebService

_

Public Function Delcurtable (Byval TBName As String) AS Boolean

Try

Return True

Catch exception

Return False

END TRY

END FUNCTION

Regarding this webservice synchronous call method, I will not explain asynchronous calls: private a as vbwebservice.dataManage 'Defines a WebService Variable Dim Ar As IasyncResultpublic Sub Callback1 (Byval Ar As IasyncResult)' 'Here you can write any code' here After the call is running, start running End Sub after the call is running.

#Region "Asynchronous Call" 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 thenexit subend ifif ar.iscompleted thendim m as boolean = a.Enddelcurtable (ar) Messagebox.show (m.tostring) end ifend sub # end region Note: "Return the result of asynchronous calls once Can call it once, if you want to execute it again, you must re-execute the method of BeGin "The above is VB.NET usage. The following is the usage 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) {string a; a = ar.asyncState.tostring (); switch (a) {copy "zhang": messagebox.show ("zhang"); break; case "wang": MessageBox .Show ("wang"); break; default: MessageBox.show ("default"); Break;

}

}

Private void btnstart_click (object sender, system.eventargs e) {system.asyncCallback cb = new asyncCallback (this.callback1); ar = a.Begindelcurtable ("zhang", cb, "zhang");}

转载请注明原文地址:https://www.9cbs.com/read-14926.html

New Post(0)