The .NET Framework platform contains some high-level components that make concurrent applications programming much easier. In Chapter 6, Using Concurrent Data Structures, we reviewed concurrent collections and data structures, and in Chapter 4, Task Parallel Library in Depth, and Chapter 5, C# Language Support for Asynchrony, we looked at Task Parallel Library and the C# language async/await
infrastructure.
Here, we will see how TPL and C# can improve your programming experience.
As an example task, let's consider leveraging a weather information from a service for each provided city, processing the information, and printing it to the console. The simple implementation will be like this:
public async Task UpdateWeather() { var cities = new List<string> { "Los Angeles", "Seattle", "New York" }; var tasks = from city in cities select new { City = city, WeatherTask = GetWeatherForAsync(city) }; foreach (var entry in tasks...