微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

有人可以在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.

原文地址:https://www.jb51.cc/aspnet/251474.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐