I am a tall (1,95m) coding & drawing enthusiast that likes all type of coding and drawing cartoons. I like to work (coding & drawing) on the go with my surface
#cypress #js #csharp
I wanted to add for those who are not that familiar with tasks, that using ConfigureAwait(false) is not only about performance issues but also about avoiding deadlocks in UI and Asp.Net applications.
In .NET you always should use "ConfigureAwait(false)" if you publish a library.
Second addition:
Using .Result within the UI Mainthread or within Asp.Net Request threads produces deadlocks. This also can be avoided using ConfigureAwait(false). But care attention if you use dependency injection. The scope may not flow with the code if you use ConfigureAwait(false).
And:
async/await introduces more complexity at CIL level and thus costs memory and CPU time. This should be taken into consideration when writing async code.
There isn't an easy answer to this question that doesn't require more explanation. There is an FAQ of sorts here: devblogs.microsoft.com/dotnet/conf...
The very short and condensed version is that it signals to the async system that you want your asynchronous code to not be marshaled back to the original calling context. I highly recommend careful study of the FAQ post for more details on the consequences of that.
I don't use c# outside on my rare unity doodles. In case anyone is familisr with f#, is there anything similar in f# (for the async computational expressiom)?
Hey there, appreciate your helpful insights concerning ConfigureAwait(false). :)
async/await introduces more complexity at CIL level and thus costs memory and CPU time. This should be taken into consideration when writing async code.
You are spot-on concerning this. For the benefit of those reading this comment, this SO post gives 2 examples concerning the added complexity at CIL level when using async / await.
When do you decide to use async code?
I'm not sure if I got your question right, but I suppose you are asking this in relation to the added complexity at CIL level. If so, Stephen Cleary's post provides a thorough explanation on this matter, and I'll summarise some of the key points here:
It’s more efficient to elide async and await
Which you have mentioned rightly. However,
it’s important to point out that each of these gains are absolutely minimal... In almost every scenario, eliding async and await doesn’t make any difference to the running time of your application.
I suggest following these guidelines:
Do not elide by default. Use the async and await for natural, easy-to-read code.
Do consider eliding when the method is just a passthrough or overload.
Stephen Cleary also provides examples of pitfalls, one concerning using the using statement, and the other concerning exceptions. He gives an amazing and concise explanation there, so I'll not copy the quotes here.
Thanks for your question! You helped me to dig deeper into this topic, which resulted in me finding Stephen's blog post.
I am a tall (1,95m) coding & drawing enthusiast that likes all type of coding and drawing cartoons. I like to work (coding & drawing) on the go with my surface
#cypress #js #csharp
Nice post!
I wanted to add for those who are not that familiar with tasks, that using
ConfigureAwait(false)
is not only about performance issues but also about avoiding deadlocks in UI and Asp.Net applications.In .NET you always should use "ConfigureAwait(false)" if you publish a library.
Second addition:
Using
.Result
within the UI Mainthread or within Asp.Net Request threads produces deadlocks. This also can be avoided usingConfigureAwait(false)
. But care attention if you use dependency injection. The scope may not flow with the code if you useConfigureAwait(false)
.And:
async/await introduces more complexity at CIL level and thus costs memory and CPU time. This should be taken into consideration when writing async code.
When do you decide to use async code?
But what does
ConfigureAwait(false)
do exactly?There isn't an easy answer to this question that doesn't require more explanation. There is an FAQ of sorts here: devblogs.microsoft.com/dotnet/conf...
The very short and condensed version is that it signals to the async system that you want your asynchronous code to not be marshaled back to the original calling context. I highly recommend careful study of the FAQ post for more details on the consequences of that.
I don't use c# outside on my rare unity doodles. In case anyone is familisr with f#, is there anything similar in f# (for the async computational expressiom)?
Hey there, appreciate your helpful insights concerning
ConfigureAwait(false)
. :)You are spot-on concerning this. For the benefit of those reading this comment, this SO post gives 2 examples concerning the added complexity at CIL level when using
async
/await
.I'm not sure if I got your question right, but I suppose you are asking this in relation to the added complexity at CIL level. If so, Stephen Cleary's post provides a thorough explanation on this matter, and I'll summarise some of the key points here:
Which you have mentioned rightly. However,
Stephen Cleary also provides examples of pitfalls, one concerning using the
using
statement, and the other concerning exceptions. He gives an amazing and concise explanation there, so I'll not copy the quotes here.Thanks for your question! You helped me to dig deeper into this topic, which resulted in me finding Stephen's blog post.
Thanks for linking that blog posts. I will read through it. Sounds very interesting!