惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - 朱胜

exeCommand 阻止浏览器事件传递 Ext js Grouping 展开和折叠方法 JS获取上传文件的绝对路径,兼容IE和FF - 朱胜 - 博客园 ASP.Net的正则表达式(RegularExpression) Extjs简介(二) Extjs框架简介(一) ASP.NET 压缩和解压缩 - 朱胜 - 博客园 ASP.NET 恢复备份Sql server - 朱胜 WPF学习2:布局(上) WPF学习笔记1 WPF生命周期和参数配置 WPF编程笔记 0:WPF概况(上部分) JavaScript判断文件大小 - 朱胜 - 博客园 clientHeight,offsetHeight和scrollHeight区别 CSS HACK(ie6-ie7-fox 兼容) 页面禁止后退的方法 upLoad控件设置禁止输入的方法 - 朱胜 - 博客园 [ASP.NET] 实现Label自动换行 - 朱胜 - 博客园 js调用web服务范例 - 朱胜 - 博客园
asp.net2.0中异步调用WebService - 朱胜 - 博客园
朱胜 · 2010-06-24 · via 博客园 - 朱胜

由于asp2.0提供了异步页的支持使异步调用WebService的性能有了真正的提升。
  使用异步页,首先要设置Async="true",异步页是在Prerender和PrerenderComplete事件间加入Begin,end异步方法实现的,Begin和End方法属于不同的线程。
  WS异步页的实现有两种方式:
  1、使用等待方法实现异步
  通用类,封装了WS
  /**//// <summary>
   /// 使用等待方法实现异步
   /// </summary>
   /// <param name="name"></param>
   /// <returns></returns>
   private Account account;
   private string username;
   public Account Account
   {
   get { return account; }
   set { account = value; }
   }
   public string Username
   {
   get { return username; }
   set { username = value; }
   }
   public IAsyncResult BeginAsyncGetAccount(object sender, EventArgs e, AsyncCallback cb, object state)
   {
  
   return vb.BeginGetAccountbyName(username,cb,state);
   }
   public void EndAsyncGetAccount(IAsyncResult ar)
   {
   account = vb.EndGetAccountbyName(ar);
   }
  
   /**//// <summary>
   /// 使用事件驱动的异步
   /// </summary>
   /// <param name="username"></param>
   public void GetAccountCompleted(Object source, VB.GetAccountbyNameCompletedEventArgs e)
   {
   account = e.Result;
   }
   public void AsGetAccount(string username)
   {
   vb.GetAccountbyNameCompleted += new GetAccountbyNameCompletedEventHandler(GetAccountCompleted);
   vb.GetAccountbyNameAsync(username)
  
   }调用方法
   protected void Page_Load(object sender, EventArgs e)
   {
   this.PreRenderComplete += new EventHandler(Page_PreRenderComplete);
   b.Username = "dinghao";
  
   AddOnPreRenderCompleteAsync(b.BeginAsyncGetAccount, b.EndAsyncGetAccount);
   }
   protected void Page_PreRenderComplete(object sender, EventArgs e)
   {
   //异步调用结束
   VB.Account a = b.Account;
   AccountIf ai = new AccountIf(a);
   ais[0] = ai;
   GridView1.DataSource = ais;
   GridView1.DataBind();
   }由于AddOnPreRenderCompleteAsync的两个委托都是Void类型,所以在通用类中要加入有返回值的属性如:Account供主调方法使用,另外委托中没有异步方法的参数信息,要加入参数的属性如:Username
  2、事件驱动的异步(2.0新增)
  调用方法:
  protected void Page_Load(object sender, EventArgs e)
   {
   this.PreRenderComplete += new EventHandler(Page_PreRenderComplete);
   b.AsGetAccount("dinghao");
  
   }
   protected void Page_PreRenderComplete(object sender, EventArgs e)
   {
   //异步调用结束
   VB.Account a = b.Account;
   AccountIf ai = new AccountIf(a);
   ais[0] = ai;
   GridView1.DataSource = ais;
   GridView1.DataBind();
   }这种调用方式,用的是*Completed事件,在*Async完成时触发,这种调用方式可以
  省去Account,Username属性,用起来比较简单

posted on 2010-06-24 23:08  朱胜  阅读(259)  评论()    收藏  举报