Async Task vs Task
Hi Friends,
In this section, thought to discuss one of the topics, which I come across too often and that is whether to do async task or simply keep as task?
Whenever, async-await gets loaded in the program, it also loads state machine which means eventually, its going to have some extra code. But that makes sense as it wraps error body as well in it. If you don’t wrap it around, then you will end up having tough time identifying or reproducing the issue as this will highlight error some where in program.cs rather than actual method.
Let us understand the same using some snippet,
Here, I have got two methods. one with async and another without doing the same job. Let’s call this first without async await like shown below.
one point to note here, I am using LinkedIn profile page here as an example, which basically needs an user agent as well which i am not supplying. This means, LinkedIn will reject these requests. Hence, this will throw error and it will look like
Now, If I do using async await, the it will flag the appropriate error like shown below
Hence, it always makes sense to use async await in conjunction with task for saving time during debugging.
I hope you guys would have liked this post.
Thanks,
Rahul Sahay
Happy Coding
Originally published at My View.