asynccall.cs

来自「asp.net经典案例资料」· CS 代码 · 共 37 行

CS
37
字号
using System;

public class WebServiceApp
{
  public static string Result = "";
  public static void Main()
  {
    Console.WriteLine("Starting to call Web Service...");

    HelloMore hm = new HelloMore();
    AsyncCallback cb 
      = new AsyncCallback(WebServiceApp.SayHelloMoreCallback);
    IAsyncResult ar = hm.BeginSayHelloMore("Async", cb, hm);

    int start = DateTime.Now.Second;
    int currentSecond = start;
    while (ar.IsCompleted == false)
    {
      if (currentSecond < DateTime.Now.Second)
      {
         currentSecond = DateTime.Now.Second;
         Console.WriteLine("Seconds Elapsed..." + (currentSecond - start).ToString() );
      }
    }

    Console.WriteLine(Result);
    Console.WriteLine("Finishing Web Service Call");
    return;
  }

  public static void SayHelloMoreCallback(IAsyncResult ar)
  {
    HelloMore hm = (HelloMore) ar.AsyncState;
    Result = hm.EndSayHelloMore(ar);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?