UnitSeven
(Solved) IHttpClientFactory problem with requests
i have Task:
private async System.Threading.Tasks.Task<Discord.FileAttachment> XTAtachmetToFileAttachment(Discord.IAttachment xAAttachment)
{
Discord.FileAttachment xFileAttachmentToReturn; // download file to Stream System.Net.Http.IHttpClientFactory xOHttpClientFactory = Bot_One.XCDependContainer.XOServiceProvider.GetService<System.Net.Http.IHttpClientFactory>(); System.Net.Http.HttpClient xHttpClient = xOHttpClientFactory.CreateClient(); System.IO.Stream xStream = await xHttpClient.GetStreamAsync(xAAttachment.Url); and so on... when i run that task concurrent (5 requests), 2 request are completed and other 3 not... and run i like this (with list): System.Collections.Generic.List<System.Threading.Tasks.Task<Discord.FileAttachment>> xTasksToExecute = new System.Collections.Generic.List<System.Threading.Tasks.Task<Discord.FileAttachment>>(); foreach (Discord.IAttachment xOCollectedAttachment in xOMessageForPosting.XEnCollectedAttachments) { xTasksToExecute.Add(System.Threading.Tasks.Task.Run( () => XTAtachmetToFileAttachment(xOCollectedAttachment) } System.Console.WriteLine($"Befor caling WhenAll."); var result = await System.Threading.Tasks.Task.WhenAll(xTasksToExecute); and i ran out of ideas what could be wrong...
Discord.FileAttachment xFileAttachmentToReturn; // download file to Stream System.Net.Http.IHttpClientFactory xOHttpClientFactory = Bot_One.XCDependContainer.XOServiceProvider.GetService<System.Net.Http.IHttpClientFactory>(); System.Net.Http.HttpClient xHttpClient = xOHttpClientFactory.CreateClient(); System.IO.Stream xStream = await xHttpClient.GetStreamAsync(xAAttachment.Url); and so on... when i run that task concurrent (5 requests), 2 request are completed and other 3 not... and run i like this (with list): System.Collections.Generic.List<System.Threading.Tasks.Task<Discord.FileAttachment>> xTasksToExecute = new System.Collections.Generic.List<System.Threading.Tasks.Task<Discord.FileAttachment>>(); foreach (Discord.IAttachment xOCollectedAttachment in xOMessageForPosting.XEnCollectedAttachments) { xTasksToExecute.Add(System.Threading.Tasks.Task.Run( () => XTAtachmetToFileAttachment(xOCollectedAttachment) } System.Console.WriteLine($"Befor caling WhenAll."); var result = await System.Threading.Tasks.Task.WhenAll(xTasksToExecute); and i ran out of ideas what could be wrong...
8 replies