-1

I have an asynch handler which inherits from HttpTaskAsyncHandler. At some line inside that handler I have a code which calls an async methods(decorated with the 'async' keyword) which executes a commands in documentDB and returns a task like in the following example: https://learn.microsoft.com/en-us/azure/cosmos-db/documentdb-dotnet-application .

Originally I had a regular generic handler, but the link shows that they changed the controller to be async so I changed my handler to inherit from HttpTaskAsyncHandler. Now, I feels like there is too much/duplicate multi threading here, my handler is now async but also inside the handler I await a method which works with documentDB api(insert operation).

Am I doing two async operation here? One because the handler is async and one because the documentDB method call is async?

MarkusEgle
  • 2,795
  • 4
  • 41
  • 61
SimpleDesign
  • 871
  • 6
  • 10
  • Where is the code? What threading and duplication are you talking about? Anyway `await` doesn't *make* an asynchronous call. It *awaits* an already asynchronous operation to finish before continuing. Similarly, the `ProcessRequestAsync` method doesn't *make* your code asynchronous, it allows you to use `async/await` or simply return a hot task to the framework. The handler knows how to await that task – Panagiotis Kanavos Aug 28 '17 at 14:06
  • thank you, this is similar to my code: public class Class1 : HttpTaskAsyncHandler { public override async Task ProcessRequestAsync(HttpContext context) { await asd(); } private async Task asd() { return await SomeMethod(); } } is it ok and makes a difference that i added the 'async' keyword to the ProcessRequestAsync method? – SimpleDesign Aug 28 '17 at 14:45
  • Never put code in comments, you need to [edit your question](https://stackoverflow.com/posts/45920795/edit) and put your code there (and properly formatted) – Scott Chamberlain Aug 28 '17 at 15:02
  • thank you scott, I will remember that. – SimpleDesign Aug 28 '17 at 18:38

1 Answers1

1

Am I doing two async operation here? YES.

what does the code mean await asd(); it commits to produce the desire result once that asynchronous operation being completed & if there are code beneath it further nature of code execution will become synchronous.

Vishal Patwardhan
  • 317
  • 1
  • 4
  • 15
  • thank you vishal, so is it ok that I added the async keyword to the method? is it ok and necessarily needed the two async operation that I'm doing here? – SimpleDesign Aug 28 '17 at 18:40