异步调用Web Service

Polling异步(Ben,End方法)


            EZweather.EZtour a = new MulFormRun.EZweather.EZtour();
            IAsyncResult myResult 
= a.BegingetWeather("西安"nullnull);
            
while (!myResult.IsCompleted)
            {
                textBox1.Text 
= "处理中";
            }
            
string[] mys = a.EndgetWeather(myResult);
            
foreach (string i in mys)
            {
                listBox1.Items.Add(i);
            }
            textBox1.Text 
= string.Empty;

 

.Net2.0中的用法

void getWeatherComplete(object sender, EZweather.getWeatherCompletedEventArgs e)
    {
        GridView1.DataSource
=e.Result;
        GridView1.DataBind();
    }
    
protected void Button2_Click(object sender, EventArgs e)
    {
        EZweather.EZtour a 
= new EZweather.EZtour();
        a.getWeatherCompleted 
+= new EZweather.getWeatherCompletedEventHandler(getWeatherComplete);
        a.getWeatherAsync(
"深圳");
    }


计时统计

System.Diagnostics.Stopwatch sw;
sw 
= new System.Diagnostics.Stopwatch();
sw.Start();
//do something
sw.Stop();
sw.ElapsedMilliseconds 
//毫秒数
posted @ 2008-12-25 17:32  chy710  阅读(69)  评论(0)    收藏  举报