asynchronous manipulators in ASP. NET 4 Developer Preview
After abandoning support for. NET 3, the ASP 4 completely embraced the Task Class library, and you don't need to write two methods for each action with no pain, and you don't need to be silly to manually The asynchronous action counter increases or decreases (AsyncManager.OutstandingOperations.Increment ()), and now you just pick up your finger, tap a few taps, and everything else is done by the system .
- public class Portalcontroller:asynccontroller {
- Public Task News (stringcity) {
- ReturnTask.Factory.StartNew (() = Runthread (city). ContinueWith (T + = {
- Returnview (Newviewstringmodel () {Text = T.result});
- });}
- Privatestringrunthread (stringinput) {
- Thread.Sleep (5000);
- Returninput;}
- }
Is it much better? Lamda can make all the more cool:
- Public Task News (stringcity) {
- ReturnTask.Factory.StartNew (() = Runthread (city). ContinueWith (t = View (newviewstringmodel{
- Text = T.result});
- }
is the ASP. NET MVC 4.0 much more concise? Lamda can make all the more cool:
public class Default1controller:asynccontroller
{
Trslms. Data.Models.DataDbContext db = new Data.Models.DataDbContext ();
//
GET:/homepage/default1/
Public task<viewresult> FooBar ()
{
StartNew Start execution return action or return value directly after ContinueWith end
Return Task.Factory.StartNew (() = {return db. USER. ToList (); }). ContinueWith (t =>{return View (T.result);});
}
}
ASP. NET MVC 4 Asynchronous Load Controller