How to determine if an AsyncController MVC thread is running in an ASP.NET application pool or in an I / O completion port

I have an ASP.NET MVC 3 application. I am using AsyncController and creating new threads. Is there a way to verify that I use I / O completion ports instead of an ASP.NET thread pool?

Is there a property in Thread.CurrentThread or somewhere else that I can check to determine where the thread works?

Here is an example of the code that I am executing

public class HomeController : AsyncController { public void CarsComplexAsync(string make) { AsyncManager.OutstandingOperations.Increment(2); System.Diagnostics.Debug.WriteLine("Enter CarsComplexAsync: " + DateTime.Now); Action getCarsAsync = () => { List<Car> cars = CarService.GetCars(make); AsyncManager.Parameters["cars"] = cars; AsyncManager.OutstandingOperations.Decrement(); }; Action getTrucksAsync = () => { List<Car> trucks = CarService.GetTrucks(make); AsyncManager.Parameters["trucks"] = trucks; AsyncManager.OutstandingOperations.Decrement(); }; getCarsAsync.BeginInvoke(null, null); getTrucksAsync.BeginInvoke(null, null); } 

 public ActionResult CarsComplexCompleted(List<Car> cars, List<Car> trucks) { cars.AddRange(trucks); return View(cars); } 

 public static class CarService { private static List<Car> _cars = new List<Car> { new Car{ Make = "Ford", Model = "F-150", Color = "White", Year = 2010}, new Car{ Make = "Chevy", Model = "Camero", Color = "Black", Year = 1984}, new Car{ Make = "Peugeot", Model = "406 Coupe", Color = "White", Year = 2010}, new Car{ Make = "Dodge", Model = "Charger", Color = "Red", Year = 1974} }; public static List<Car> GetCars(string model) { Thread.Sleep(5000); List<Car> cars = _cars; return cars; } public static List<Car> GetTrucks(string make) { Thread.Sleep(5000); List<Car> cars = _cars; return cars; } } 
+6
source share
1 answer

Is there a way to verify that I use I / O completion ports instead of an ASP.NET application pool?

Without looking at your code, as it will depend on the API you are using.

For example, HttpWebRequest.BeginGetResponse uses I / O completion ports. On the other hand, if you have an intensive processor task that you run in a separate thread that you created manually, then you do not use I / O completion ports.

Is there a property in Thread.CurrentThread or somewhere else that I can check to determine where the thread works?

The terminating port means that there is no thread, because if there was a thread, as if you were executing a thread. Basically, how the I / O ports work, you start some kind of I / O operation and register a CP, and then free all the threads and return. During the operation, there are no threads in the application associated with it. As soon as the operation completes, the port is signaled and a thread is created or pulled from the pool to complete the request.

+8
source

Source: https://habr.com/ru/post/885629/


All Articles