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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/aspnet/251474.html

猜你在找的asp.Net相关文章