A working of Asynchronous Controllers is used when users send a request to Asynchronous Controllers the asp.net will provide a thread from Thread pool to handle the request. The request is small then it will process it in normal way but in case if the processing is taking too long time to complete then it will return the process to
thread pool for handling other request and whenever the asynchronous operation will complete, it notifies ASP.NET then asp.net gets a worker thread from the thread pool to process the remaining of the request, which includes rendering the response.
A convention required for following when using Asynchronous Controllers. For Asynchronous Controllers we have two methods:-
1. Async
2. Completed
Async
The async method will return void and it will start the asynchronous process. The syntax of the async method in asp.net MVC is shown below
Action Name Async
Completed
The method is called when the asynchronous process is complete. The syntax of the Completed method in asp.net MVC is shown below
Action Name Completed
We will learn both these methods in detail with an example. In this example we used web service (Weatherservice) in IndexAsync method in that we created a proxy client which will take Country name as an input and will Return Cities then we will store cities in TempData["ListofCities"] when process will complete then it will call IndexCompleted() Method from which we will display result on view.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcAttribute.Controllers
{
public class Default2Controller : AsyncController
{
public void IndexAsync()
{
Weatherservice.GlobalWeatherSoapClient objservice = new Weatherservice.GlobalWeatherSoapClient();
TempData["ListofCities"] = objservice.GetCitiesByCountry("India");
}
public ContentResult IndexCompleted()
{
string Result = TempData["ListofCities"].ToString();
return Content(Result);
}
}
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
A working of Asynchronous Controllers is used when users send a request to Asynchronous Controllers the asp.net will provide a thread from Thread pool to handle the request. The request is small then it will process it in normal way but in case if the processing is taking too long time to complete then it will return the process to thread pool for handling other request and whenever the asynchronous operation will complete, it notifies ASP.NET then asp.net gets a worker thread from the thread pool to process the remaining of the request, which includes rendering the response.
A convention required for following when using Asynchronous Controllers. For Asynchronous Controllers we have two methods:-
1. Async
2. Completed
Async
The async method will return void and it will start the asynchronous process. The syntax of the async method in asp.net MVC is shown below
Completed
The method is called when the asynchronous process is complete. The syntax of the Completed method in asp.net MVC is shown below
We will learn both these methods in detail with an example. In this example we used web service (Weatherservice) in IndexAsync method in that we created a proxy client which will take Country name as an input and will Return Cities then we will store cities in TempData["ListofCities"] when process will complete then it will call IndexCompleted() Method from which we will display result on view.