开发者

Async Controller asp.net mvc 2.0

开发者 https://www.devze.com 2022-12-12 10:58 出处:网络
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(VS

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(VS.100).aspx

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?

Example, i have:

Image orgImage = _db.getImagebyGUID(guid);
string date = orgImage.CREATE_DATE.toString();
Image newImage = _d开发者_JS百科b.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...

Thank you very much


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;
}

And the invoke 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消