簡單的異步 Web 方法
為舉例說明異步 Web 方法
[WebService]
public class SyncWebService : System
{
[WebMethod]
public string LengthyProcedure(int milliseconds)
{
System
return
}
}
現在我們將 LengthyProcedure 轉換為異步 Web 方法
當委托完成時
[WebService]
public class AsyncWebService : System
{
public delegate string LengthyProcedureAsyncStub(
int milliseconds);
public string LengthyProcedure(int milliseconds)
{
System
return
}
public class MyState
{
public object previousState;
public LengthyProcedureAsyncStub asyncStub;
}
[ System
public IAsyncResult BeginLengthyProcedure(int milliseconds
AsyncCallback cb
{
LengthyProcedureAsyncStub stub
= new LengthyProcedureAsyncStub(LengthyProcedure);
MyState ms = new MyState();
ms
ms
return stub
}
[ System
public string EndLengthyProcedure(IAsyncResult call)
{
MyState ms = (MyState)call
return ms
}
}
From:http://tw.wingwit.com/Article/os/fwq/201311/10270.html