Skip to main content
added 56 characters in body
Source Link
David
  • 220.8k
  • 42
  • 245
  • 337

Follow the async mantra of "async all the way down". Basically, you should almost never call .Result on a task. In the majority of cases, your calling method should also be async. Then you can simply await the result of the operation:

public async Task<ActionResult> TestSSN() { //... var apiResponse = await GetUsTraceApiHealth(); string responseBody = await apiResponse.Content.ReadAsStringAsync(); //... } 

It should be up to the application host at the top level (in this case ASP.NET and the web server) to handle the synchronization context. You shouldn't try to mask an asynchronous operation as a synchronous one.

Follow the async mantra of "async all the way down". Basically, you should almost never call .Result on a task. In the majority of cases, your calling method should also be async. Then you can simply await the result of the operation:

public async Task<ActionResult> TestSSN() { //... string responseBody = await apiResponse.Content.ReadAsStringAsync(); //... } 

It should be up to the application host at the top level (in this case ASP.NET and the web server) to handle the synchronization context. You shouldn't try to mask an asynchronous operation as a synchronous one.

Follow the async mantra of "async all the way down". Basically, you should almost never call .Result on a task. In the majority of cases, your calling method should also be async. Then you can simply await the result of the operation:

public async Task<ActionResult> TestSSN() { //... var apiResponse = await GetUsTraceApiHealth(); string responseBody = await apiResponse.Content.ReadAsStringAsync(); //... } 

It should be up to the application host at the top level (in this case ASP.NET and the web server) to handle the synchronization context. You shouldn't try to mask an asynchronous operation as a synchronous one.

Source Link
David
  • 220.8k
  • 42
  • 245
  • 337

Follow the async mantra of "async all the way down". Basically, you should almost never call .Result on a task. In the majority of cases, your calling method should also be async. Then you can simply await the result of the operation:

public async Task<ActionResult> TestSSN() { //... string responseBody = await apiResponse.Content.ReadAsStringAsync(); //... } 

It should be up to the application host at the top level (in this case ASP.NET and the web server) to handle the synchronization context. You shouldn't try to mask an asynchronous operation as a synchronous one.