有人可以在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”.
编辑
解决方法
我问过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.