ASP. NET MVC 4 Asynchronous Load Controller

Source: Internet
Author: User

 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 .

  

    1. public class Portalcontroller:asynccontroller {
    2. Public Task News (stringcity) {
    3. ReturnTask.Factory.StartNew (() = Runthread (city). ContinueWith (T + = {
    4. Returnview (Newviewstringmodel () {Text = T.result});
    5. });}
    6. Privatestringrunthread (stringinput) {
    7. Thread.Sleep (5000);
    8. Returninput;}
    9. }

Is it much better? Lamda can make all the more cool:

    1. Public Task News (stringcity) {
    2. ReturnTask.Factory.StartNew (() = Runthread (city). ContinueWith (t = View (newviewstringmodel{
    3. Text = T.result});
    4. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.