Correcting Common Async/Await Mistakes in .NET 8 - Brandon Minnick - NDC Porto 2023
Vložit
- čas přidán 20. 12. 2023
- This talk was recorded at NDC Porto in Porto, Portugal. #ndcporto #ndcconferences #dotnet #concurrency #softwaredeveloper
Attend the next NDC conference near you:
ndcconferences.com
ndcporto.com/
Subscribe to our CZcams channel and learn every day:
/@NDC
Follow us on our Social Media:
/ ndcconferences
/ ndc_conferences
/ ndc_conferences
Did you know that the .NET compiler turns our async methods into classes? And that .NET adds a try/catch block to each of these classes, potentially hiding thrown exceptions? It's true!
In this session, we will learn how to best use async/await in C# by analyzing how .NET compiles our async code.
Join me as we take an existing app and optimize its async code together, showing off performance gains, better exception handling, improved run-time speed, and smaller app size! - Věda a technologie
A task really is just work that will be completed at a later time. In some contexts, it may not run on a different thread in the thread pool, although thread switching is the most common scenario. It never creates a thread as far as I am aware, but just cycles through the thread pool. Additionally, the primary goal of async/await is to free up the UI and to make background tasks easier, which is a different problem than parallel processing with different design considerations.
> It never creates a thread as far as I am aware.
Depends on the scheduler. In theory TaskCreationOptions.LongRunning signals to the scheduler that creating a new thread is desirable.
Very useful information, Tank you very much.
Missed the biggest problem with async void: unhandled exceptions will bring the entire process down (depending on the synchronization context).
Thanks for sharing!
There is no thread, neo
Good explanation. Thanks!
Nice!
Great talk!
How is the "available thread" chosen? Does .NET have a scheduler for this?
Brandon seems like a nice, friendly guy; but this talk on async/await that he keeps doing is flimsy at best and dangerous at worst. The conflation of threads and tasks being the most egregious mistake.
“There’s a threadpool. We don’t have time to dive into it today” leads to so much bad, async code. Unfortunately, async/await is advanced stuff and hand waving the complexity away is problematic.
Out of curiosity. Is there any resource you would recommend? I'd love to learn more about async/await specifically since it's such an abstract concept.
@@oraliticalI think the post "There Is No Thread" from Stephen Cleary is a good start.
You cannot say that value types are leaving in the stack. It's a big oversimplification