加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.net webforms中的异步页面处理示例(.NET 2.0)

发布时间:2020-12-16 00:06:56 所属栏目:asp.Net 来源:网络整理
导读:有人可以在ASP.NET Webforms 2.0中为我提供一个简单的异步页面处理示例(我正在使用VS 2010,所以像lambdas这样的新语法可以)吗? 我有一些长时间运行的请求,我不想绑定IIS线程. 为简单起见,假设我当前的代码如下所示: protected void Page_Load(object sende
有人可以在ASP.NET Webforms 2.0中为我提供一个简单的异步页面处理示例(我正在使用VS 2010,所以像lambdas这样的新语法可以)吗?

我有一些长时间运行的请求,我不想绑定IIS线程.

为简单起见,假设我当前的代码如下所示:

protected void Page_Load(object sender,EventArgs e)
{
    string param1 = _txtParam1.Text;
    string param2 = _txtParam2.Text;

    //This takes a long time (relative to a web request)
    List<MyEntity> entities = _myRepository.GetEntities(param1,param2);

    //Conceptually,I would like IIS to bring up a new thread here so that I can
    //display the data after it has come back.
    DoStuffWithEntities(entities);

}

如何修改此代码以使其异步?假设我已经在aspx页面中设置了async =“true”.

编辑

我想我想出了如何得到我正在寻找的东西.我已将示例代码放在答案here中.请随意指出可以进行的任何缺陷或更改.

解决方法

我问过ASP.NET团队的一些人.这是他们给我的电子邮件回复,现在,给你.

All that code ends up doing is spinning up a new thread and performing delegate invocation on that thread. So now there are two threads running: the request thread and the new thread. Hence this sample actually has worse performance than the original synchronous code would have had.

See 07000 for a sample on how to write and consume async methods in ASP.NET.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读