#Asynchronous programming in C# is an effective way to solve blocked activities or delayed access. If an activity is blocked like this in the synchronization process, then the entire application will wait and take more time. The application stopped responding. Using asynchronous methods, the application can also continue to perform other tasks.
The async and await keywords in C# are used for asynchronous programming. Using them, you can use .NET Framework resources, .NET Core, and more. Asynchronous methods defined using the async keyword are called asynchronous methods.
For applications with GUI, please check the content queue if there are unprocessed tasks, take them out and process them first. The code is executed synchronously, and unprocessed tasks are completed first. If processing takes longer than expected, the application will display a Stopped Responding message.
Let us see what was discussed above -
private void OnRequestDownload(object sender, RoutedEventArgs e) { var req = HttpWebRequest.Create(_requestedUri); var res = req.GetResponse(); }
To solve the above problem, use async and await keywords -
private async void OnRequestDownload(object sender, RoutedEventArgs e) { var req= HttpWebRequest.Create(_requestedUri); var res = await req.GetResponseAsync(); }
The above is the detailed content of Asynchronous programming in C# using the Async and Await keywords. For more information, please follow other related articles on the PHP Chinese website!