0

I have a sync method as below:

public ActionResult Insert([FromBody] Model model) { }

and I also have an async method:

_myMethodAsync();

My async method returns int. If I do like this I have to edit everything

public async Task<ActionResult> Insert(...){
...
await _myMethodAsync();
...
}

Normally when I add without await I get wrong results.

public ActionResult Insert([FromBody] Model model)
{
    //...
    _myMethodAsync();
    //...
}

1 Answers1

1

Call it with await. The compiler will instruct you on what to do next: change Insert to an async method and change its result type from ActionResult to Task<ActionResult>.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810