Linked Questions

774 votes
23 answers
577k views

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() { ...
Rachel's user avatar
  • 133k
290 votes
12 answers
348k views

I have an async method: public async Task<string> GenerateCodeAsync() { string code = await GenerateCodeService.GenerateCodeAsync(); return code; } I need to call this method ...
Catalin's user avatar
  • 11.8k
453 votes
2 answers
479k views

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 ...
Lukas K's user avatar
  • 6,450
148 votes
6 answers
111k views

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 ...
spoonraker's user avatar
  • 1,725
141 votes
4 answers
257k views

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 ...
arp's user avatar
  • 1,443
20 votes
3 answers
24k views

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(); // ...
pm100's user avatar
  • 50.6k
2 votes
2 answers
13k views

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 ...
Vicky's user avatar
  • 23
2 votes
3 answers
3k views

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 ...
DiskJunky's user avatar
  • 5,021
1 vote
1 answer
3k views

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 ...
Rajika Imal's user avatar
1 vote
0 answers
1k views

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()) { ...
TWilly's user avatar
  • 4,953
1 vote
1 answer
1k views

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 ...
TheLogicMan's user avatar
0 votes
1 answer
366 views

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 ...
Laser42's user avatar
  • 764
0 votes
1 answer
432 views

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 ...
hsbsid's user avatar
  • 341
2 votes
2 answers
319 views

I have the following code. The async call never returns anything. Even for google.com. try { using ( var client = new HttpClient()) { ...
user88975's user avatar
  • 630
0 votes
1 answer
242 views

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 ...
Diego's user avatar
  • 2,390