Asyn Task in Asp.net 2.0

async page 是Asp.net 2.0中的新特征。
None.gif public  partial  class  SlowMultiAsync : Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  Slow slowWebservice 
= new Slow();
InBlock.gif  
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    PageAsyncTask task1 
=
InBlock.gif      
new PageAsyncTask(
InBlock.gif      
new BeginEventHandler(BeginGetAsyncData),
InBlock.gif      
new EndEventHandler(EndGetAsyncData),
InBlock.gif      
new EndEventHandler(TimeoutGetAsyncData),
InBlock.gif      
"task1"//this is supplemental state (an object parameter) in which you can pass anything
InBlock.gif
      true); //this is whether you want to run in parallel or serially
InBlock.gif
    PageAsyncTask task2 =
InBlock.gif      
new PageAsyncTask(
InBlock.gif      
new BeginEventHandler(BeginGetAsyncData),
InBlock.gif      
new EndEventHandler(EndGetAsyncData),
InBlock.gif      
new EndEventHandler(TimeoutGetAsyncData),
InBlock.gif      
"task2",
InBlock.gif      
true);
InBlock.gif    PageAsyncTask task3 
=
InBlock.gif      
new PageAsyncTask(
InBlock.gif      
new BeginEventHandler(BeginGetAsyncData),
InBlock.gif      
new EndEventHandler(EndGetAsyncData),
InBlock.gif      
new EndEventHandler(TimeoutGetAsyncData),
InBlock.gif      
"task3",
InBlock.gif      
true);
InBlock.gif    RegisterAsyncTask(task1);
InBlock.gif    RegisterAsyncTask(task2);
InBlock.gif    RegisterAsyncTask(task3);
ExpandedSubBlockEnd.gif  }

InBlock.gif 
InBlock.gif  IAsyncResult BeginGetAsyncData(Object src, EventArgs args,
InBlock.gif                                                           AsyncCallback cb, Object state)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
return slowWebservice.BeginHelloWorld(cb, state);
ExpandedSubBlockEnd.gif  }

InBlock.gif 
InBlock.gif  
void TimeoutGetAsyncData(IAsyncResult ar)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    Response.Write(
"<strong>async get data timed out</strong><br />");
ExpandedSubBlockEnd.gif  }

InBlock.gif 
InBlock.gif  
void EndGetAsyncData(IAsyncResult ar)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    
string ret = slowWebservice.EndHelloWorld(ar);
InBlock.gif    
// use result to prepare response heredot.gif
ExpandedSubBlockEnd.gif
  }

InBlock.gif  
//dot.gif
ExpandedBlockEnd.gif
}

None.gif

转载于:https://www.cnblogs.com/yuxz2k/archive/2005/03/19/121925.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值