C # MVC step-by-step operations

Source: Internet
Author: User

1. Establish homecontroller class and inherit asynccontroller

The token generation is as follows:

View code

   Public   Class Homecontroller: asynccontroller
{
Public Void Indexasync ()
{
Viewbag. Message = " Welcome to ASP. net mvc! " ;
Asyncmanager. outstandingoperations. increment ();
VaR Task = task. Factory. startnew () => dostuff ( " Some other stuff " ));
Task. continuewith (t =>
{
Asyncmanager. Parameters [ " Model " ] = T. result;
Viewbag. Message = T. result;
Asyncmanager. outstandingoperations. decrement ();
});

}
Private String Dostuff ( String Input)
{
Thread. Sleep ( 5000 );
Return Input;
}
Public Actionresult indexcompleted ( String Model)
{
Return View ();
}

}

2. The method indexasync for defining the specific step is also Acton. Note that. The method must return void.

The preceding method name is index + asnc. You must add asnc.

In this method, add a processing method. In this example

VaR task = task. Factory. startnew () => dostuff ("some other stuff "));
Task. continuewith (t =>
{
Asyncmanager. Parameters ["model"] = T. result;
Viewbag. Message = T. result;
Asyncmanager. outstandingoperations. decrement ();
});

3. Start in the next step

Asyncmanager. outstandingoperations. increment ();

4. End of the processing process

Asyncmanager. outstandingoperations. decrement ();

5. Variable Volume Changes

Asyncmanager. Parameters ["model"] = T. result;

Among them, the model is the variable name of the volume to be renewed.

In the same way, you can also use the data storage method in the collection, or modify the volume, for example, viewbag. Message = T. result;

6. After completing the steps, return the data volume indexcompleted

Including region index + completed

Such as this method

Public actionresult indexcompleted (String Model)
{
Return view ();
}

In this example, the model parameter number is the value of asyncmanager. Parameters ["model"] = T. Result; generated bytes.

If asyncmanager. Parameters defines a variable, then adding it to the parameter data of this method will lead over.

Data in the same collection is shared.

7. Using this collection method is

Home/Index

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.