This question has already been answered:
There is some misunderstanding with the operation of asynchronous code, in connection with which I ask for help. The following function hangs up the program:
private List<ContractsList> GetContractsDetail(contracts) { List<string> contractsList = new List<string>(); // Сюда буду ложить ответы Task[] requests = new Task[contracts.Length]; // Создаю массив для моих тасков Uri Uri = new Uri(Settings.CONTRACT_DETAIL_URI); for (int i = 0; i < contracts.Length; i++) // По каждому контракту { HttpRequest ContractRequest = new HttpRequest(); //Это мой класс для работы с HttpClient Dictionary<string, string> data = new Dictionary<string, string>() { ["access_token"] = token, ["contract_id"] = contracts[i] }; // Данные для GET запроса requests[i] = ContractRequest.Get(Uri, data); // Моя обертка над HttpClient.GetAsync } Task.WaitAll(requests); // Тут зависает программа // Тут еще код, который я не дописал return contractsList; } According to information on the Internet I do not fully understand:
- Does
WaitAlllikeawait? And if so, why does the program hang? - Do my Tasks start at all?
- Where in the code am I wrong? =)