Linked Questions
15 questions linked to/from Why use HttpClient for Synchronous Connection
774 votes
23 answers
577k views
How would I run an async Task<T> method synchronously?
I am learning about async/await, and ran into a situation where I need to call an async method synchronously. How can I do that? Async method: public async Task<Customers> GetCustomers() { ...
290 votes
12 answers
348k views
Calling async method synchronously
I have an async method: public async Task<string> GenerateCodeAsync() { string code = await GenerateCodeService.GenerateCodeAsync(); return code; } I need to call this method ...
453 votes
2 answers
479k views
When correctly use Task.Run and when just async-await
I would like to ask you on your opinion about the correct architecture when to use Task.Run. I am experiencing laggy UI in our WPF .NET 4.5 application (with Caliburn Micro framework). Basically I am ...
148 votes
6 answers
111k views
What's the "right way" to use HttpClient synchronously?
I used quote marks around "right way" because I'm already well aware that the right way to use an asynchronous API is to simply let the asynchronous behavior propagate throughout the entire ...
141 votes
4 answers
257k views
Effectively use async/await with ASP.NET Web API
I am trying to make use of the async/await feature of ASP.NET in my Web API project. I am not very sure whether it will make any difference in performance of my Web API service. Please find below the ...
20 votes
3 answers
24k views
best way to use the nice .net 4.5 HttpClient synchronously
I like the new System.Net.Http.HttpClient class. It has a nice simple API, it doesn't throw on normal errors. But its async only. I need code that goes (deep inside a server) foo(); bar(); // ...
2 votes
2 answers
13k views
httpclient async/await or not
I'm using one httpclient instance to send multiple requests to rest web api to get data. Here is what my code looks like: First I have a control layer that calls the data layer for data. public ...
2 votes
3 answers
3k views
Why use HttpClient over HttpWebRequest for synchronous requests
In my scenario, I have to send data from one web application to a webapi which is an effective data store. The requests are necessarily synchronous and I most definitely want an Exception thrown if ...
1 vote
1 answer
3k views
C# HttpClient.PostAsync doesn't return or throw an error
I have a Windows service making an HTTP POST request. The REST endpoint is working and it was tested separately. After calling PostAsync, the debugger doesn't continue or throw an error. What would be ...
1 vote
0 answers
1k views
asp.net HttpClient throws exception on 400 errors when sending synchronous requests
The following code for me is throwing an exception when I get a 400 error. Thus I'm never able to get return response as the exception is always caught. using (var client = new HttpClient()) { ...
1 vote
1 answer
1k views
Why can't I use HttpClient for Syncrhonous calls from ASP.Net?
I'm using a client library for accessing a 3rd party API. The library was generated by NSwagStudio from Swagger documentation. The app I'm working on is entirely synchronous in all its calls and ...
0 votes
1 answer
366 views
Multiple async Ado.net sql inserts in intent service
I have an intent service that do the following: extracts from intent a string parameter, composes http query using the parameter, executes it using async task and System.Net.Http, parses received ...
0 votes
1 answer
432 views
How do I convert this filestream from an API to a PDF or XML file?
I am trying to use an API to download documents which will be in either PDF or Word document formats. The service gives directions only up to how to construct the request URL, which I have done. The ...
2 votes
2 answers
319 views
Windows phone httpclient not working
I have the following code. The async call never returns anything. Even for google.com. try { using ( var client = new HttpClient()) { ...
0 votes
1 answer
242 views
MVC call api controller PostAsJsonAsync from Session_Start
I am doing an MVC 5 APP and i am calling a Api Controller using PostAsJsonAsync like this HttpResponseMessage response = await client.PostAsJsonAsync(apiUrl + "Method/Action",param); I got this error ...