I use Windows.Web.Http.HttpClient
in my UWP Windows 10 app. I have created a single instance of the HttpClient
in my app and re-using the connection for all the HTTP calls. Everything works fine, except for the parallel HTTP calls.
Whenever I iniate a parallel HTTP request, At first time the paralell threads throws the below COMException. I catch this exception and resend the http calls and it succeeds. After a while, again if i start parallel thread, its failing again.
Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll
WinRT information: A concurrent or interleaved operation changed the state of the object, invalidating this operation.
Tried surfing and couldn't get the solution. Does anyone faced this issue and got solution?
Here is the code sample:
httpClient is a single reusable instance.
var response = await httpClient.SendRequestAsync(reqMsg).AsTask(cts.Token); if (response.IsSuccessStatusCode) { if (isBufferResponseRequired) { return await response.Content.ReadAsBufferAsync(); } else { return await response.Content.ReadAsStringAsync(); } }
Im creating multiple threads using Tasks.Run() and access the httpClient paralelly.