0

Will the IO bound code in this context be put on the IO thread? Or do I need to make the Get method async and await PassThroughTask?

//Some controller class 

[HttpGet]
public Task<ActionResult> Get()
{
    PassThroughTask(); 
    return Ok("passthrough");
}

public async Task PassThroughTask()
{
    //Is this going to stop the IoBoundWork from going to the IO thread? 
    await SomeIoBoundWorkAsync();
}

public async Task SomeIoBoundWorkAsync(){ //await async io stuff}
GSerg
  • 76,472
  • 17
  • 159
  • 346
awright18
  • 2,255
  • 2
  • 23
  • 22
  • 1
    FYI You can change your method signature to include the async keyword, and then await the call to PassThroughTask like this: public async Task Get() – Yves Rochon Sep 13 '19 at 19:59
  • 3
    `do I need to` - yes. What you currently have is called "[fire and forget](https://stackoverflow.com/q/46053175/11683)". `Will the IO bound code in this context be put on the IO thread?` - there is [no thread](https://stackoverflow.com/q/37419572/11683). – GSerg Sep 13 '19 at 20:00
  • Yes, you need to make the `Get()` method `async` or it won't work. – Vilx- Sep 13 '19 at 20:00
  • Any documentation that anyone can point to or blogs? Because I tend to agree, just looking for evidence. – awright18 Sep 13 '19 at 20:04
  • 2
    @awright18 Apart from the [links above](https://stackoverflow.com/questions/57929614/async-await-asp-net-core-when-is-async-required#comment102276890_57929614), everything starting from https://blog.stephencleary.com/2012/02/async-and-await.html, including https://blog.stephencleary.com/2013/11/there-is-no-thread.html which is already referenced from https://stackoverflow.com/q/37419572/11683. – GSerg Sep 13 '19 at 20:06
  • I'll check those out thanks @GSerg – awright18 Sep 13 '19 at 20:08

0 Answers0