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