Based on the answer to the second question:
I am using the extension method and the argument I propose to use the timeout with the HTTP client class and do not hang or take any feedback from it.
Public stable work & lt; T & gt; WithTimeout & LT; T & gt; (This task is & lt; t & gt; Task, TimeSpan Timeout) {var Deli = task.ContinueWith (t = & gt; t.Result, New CancellationTokenSource (timeout). Token); Return function. When someone (work, delay) Anavap (); }
Therefore, any "Task Not Deteriorating" can end any time that ends with calling the HTTP client:
Task & lt; HTTPPS Messaging & gt; _response = httpClient.PostAsJsonAsync & lt; Object & gt; (Target, new object ()). WithTimeout & lt; HTTPRPS Pormes & gt; (HttpClient.Timeout); Now, when applying this, by using the populated working array with a loop, I expected all the functions to run in parallel and end in a specified timeout value. To show just a sample, I am setting the timeout in 400ms, although the next line after the job When all (work) line hits after about 20 seconds. Public async Tasks & lt; Jobbject & gt; GetResponse (Task Request, TimeSpain Timeout) {Timespan Timeout = Timespan. From Milliseconds (400); HTTP Client HTTP Client = New HTTP Client (); HttpResponseMessage Response = Wait httpClient.PostAsJsonAsync & LT; String & gt; (String.Format ("{0} API / GetResponse", last point), localRequest.ToString ()) WithTimeout. & Lt; HttpResponseMessage & gt; (Timeout); Wait for the return. Readsink & lieutenant; Jobtext & gt; (). Timeout & lt; Jobs & gt; (Timeout); }
Async calling method:
Task & LT; JObject & gt; [] Functions = New Tasks & LT; JObject & gt; [TotalResultCounter]; FORHEES (JOBISE REQUEST IN AARR) {WORK [COUNTER] = GETRASSPONES (REQUEST); } Awaiting work. When all (work); MyNextMethod ();
Would not it be expected that 500 ms and the next line will be completed? Why does it take about twenty seconds to reach the MyNextMethod line? Maybe when I'm doing anything wrong in PostAsJsonAsync / ReadAsAynSync set timeout?
The timeout extension method works well enough.
When I'm waiting for the use of the keyword, it seems like it is waiting to complete, though not using fixed timeout:
HttpResponseMessage response = httpclient.PostAsJsonAsync (String.Format ("{0} API / GetSupplierResponse", endpoint), localRequest.ToString ()). Timeout);
If I change it:
Tasks & lt; HTTPRPS Pormes & gt; Feedback = httpClient.PostAsJsonAsync & lt; String & gt; (String.Format ("{0} API / GetResponse", End Point), Local Request.ToString ()). Timeout & lt; Httprespermess messaging & gt; (Timeout);
It's fast.
But then how do I get results? I need to wait a readAsAsync method to use.
JObject result = wait response.Content.ReadAsAsync & LT; JObject & gt; () WithTimeout & LT; JObject & gt; (Timeout);
I use it, it takes a lot of time, 20 seconds to complete my loop from around 200 objects.
The PostAsJsonAsync and ReadAsAsync should be handled as an independent work that will not respect the specified timeout in httpclient? Or use these methods more than 500 millimeters, and that is why using a loop takes a lot of things?
Any help / conceptual explanation will be appreciated.
No comments:
Post a Comment