![]() While (Console.ReadKey().Key != ConsoleKey.Enter)Ĭonsole.WriteLine("Press the ENTER key to cancel.") Ĭonsole.WriteLine("\nENTER key pressed: cancelling downloads. Replace the existing method with the following: static async Task Main()Ĭonsole.WriteLine("Application started.") Ĭonsole.WriteLine("Press the ENTER key to cancel.\n") ![]() The main entry point into the console application is the Main method. The s_urlList holds all of the URLs that the application plans to process. The HttpClient exposes the ability to send HTTP requests and receive HTTP responses. The CancellationTokenSource is used to signal a requested cancellation to a CancellationToken. Static readonly IEnumerable s_urlList = new string Static readonly HttpClient s_client = new HttpClient In the Program class definition, add these three fields: static readonly CancellationTokenSource s_cts = new CancellationTokenSource() Replace the existing using statements with these declarations: using System Use the Ctrl + Shift + Esc keyboard shortcut. Open Start, do a search for Task Manager and click the result. Open the Program.cs file in your favorite code editor. Right-click the Taskbar and click on Task Manager. You can create one by using the dotnet new console command or from Visual Studio. We recommend Visual Studio, Visual Studio Code, or Visual Studio for MacĬreate a new.Integrated development environment (IDE).Writing an async application that supports cancellation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |