异步控制器asp.net的MVC 2.0 [英] Async Controller asp.net mvc 2.0
问题描述
目前MS已经发布asp.net MVC 2.0测试版与AsyncController的,但很少有文献在对此次除了一个文件:的 http://msdn.microsoft.com/en-us/library/ee728598%28VS.100%29.aspx
Currently MS has been release asp.net MVC 2.0 beta with the AsyncController in it but there are very few document about this except one document at: http://msdn.microsoft.com/en-us/library/ee728598%28VS.100%29.aspx
这微软显示有制作的可AsyncController的过程中使用的事件的示例
The example from microsoft show that there is an event was used in the process of making an AsyncController.
不过,也有我这样的人,谁不使用任何事件与减量工作,并希望从迁移到同步异步控制器......那么,有没有办法来处理呢?
However, there are people like me, who do not use any event to work with the Decrement and wanting to migrate a controller from Sync to Async... So is there any way to handle this?
例如,我有:
Image orgImage = _db.getImagebyGUID(guid);
string date = orgImage.CREATE_DATE.toString();
Image newImage = _db.getImagebyGUID(guid2);
string date2 = newImage .CREATE_DATE.toString();
有没有使用异步事件没有因为有很多很多课没有实现事件回调任何可能的方式...
is there any possible way to use the Async without event because there are lot lot of class that do not implement event callback...
非常感谢你。
推荐答案
您总是可以把这个code到一个方法,创建委托给此方法和异步调用它:
You could always put this code into a method, create a delegate to this method and invoke it asynchronously:
public string DoWork()
{
Image orgImage = _db.getImagebyGUID(guid);
string date = orgImage.CREATE_DATE.toString();
Image newImage = _db.getImagebyGUID(guid2);
string date2 = newImage .CREATE_DATE.toString();
return date + date2;
}
和的调用code:
AsyncManager.OutstandingOperations.Increment();
Func<string> doWorkHandler = DoWork;
doWorkHandler.BeginInvoke(ar =>
{
var handler = (Func<string>)ar.AsyncState;
AsyncManager.Parameters["date"] = handler.EndInvoke(ar);
AsyncManager.OutstandingOperations.Decrement();
}, doWorkHandler);
这篇关于异步控制器asp.net的MVC 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!