What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial

  Рет қаралды 70,749

tutorialsEU

tutorialsEU

3 жыл бұрын

🚀 Master C# and .NET programming EASILY with our best-selling C# Masterclass: bit.ly/47Hk3u7
What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial
The world of asynchronous programming can be daunting at first. Using async and await in C# is a proven way to write code that does not block the main thread, which means it will scale better and be responsive even when dealing with long-running tasks such as IO operations. This video will cover what ASYNC and AWAIT are, how they work, and best practices for using them together.
Asynchronous programming
Asynchronous programming is a means of parallel programming in which a unit of work runs separately from the main application
Normally, any code runs straight along, with only one thing happening at once(line by line). If a method calls another method, it has to wait for the other method to finish and return, and until that happens, the entire program is essentially stopped from the user's perspective. Even the UI would freeze and look unresponsive until the task is done.
This is where Asynchronous programming comes in handy.
Asynchronous programming is a means of parallel programming in which a unit of work runs separately from the main application.
Now when should we make our apps run tasks in parallel?
Let’s look at the following real-world scenario from the MS Doc.
Imagine we are cooking breakfast.
We want to make coffee, eggs, and bacon with some toast and jam, and some juice to wash it all down : ).
If we wait for each task to be done to move on to the next task, it will take around 30 minutes. But if you think about it, we don’t need to wait for the eggs to be done to fry the bacon!.
This is an asynchronously prepared breakfast. We can actually speed up this process and optimize it using the Asynchronous method.
Now using the Asynchronous method.
We can first pour the coffee, then start with frying the eggs and the bacon and turning on the toaster at the same time!.
Once the toast is made, we can put some jam on it, pour the juice, and the breakfast is ready!.
So tasks that do not depend on other tasks like frying the eggs and the bacon can be started together. Tasks that depend on other tasks like putting jam on toast must wait for the toasting step to be done. Of course, don’t forget to take off the eggs and bacon, so you don’t burn them ;).
This whole process will take less than 20 minutes, thanks to the Asynchronous method of preparing breakfast.
So how can we apply this approach to our programs ?.
.
tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x

Пікірлер: 65
@tutorialsEU
@tutorialsEU Жыл бұрын
🚀Master C# and .NET programming EASILY with our best-selling C# Masterclass:
@stefanlabuschagne6905
@stefanlabuschagne6905 14 күн бұрын
In Short
@Rodioser
@Rodioser Жыл бұрын
I struggled, and I'd say that I'm still struggling with understanding of how async works. But surely I'm making progress in understanding it and this video was a big help. For me it's the best explanation of async that I've seen.
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
The other videos on youtube explaining asynchronous programming is much more difficult to understand. But you have been able to explain this in a more simple and easy way. Thank you for making such great effort. I hope you have a great day and achieve much more success in your life being able to gain more knowledge across all areas.
@Felipe-mg1pw
@Felipe-mg1pw Жыл бұрын
You should definitely not be using Thread.Sleep() inside an asynchronous method. Use Task.Delay() instead.
@frosky9497
@frosky9497
For people that still dont get it , how it works codewise
@AllAboutDataTechnology
@AllAboutDataTechnology
this is the best tutorial on async and await that I have seen. Clear and consise examples given.
@aricwilliamsdeveloper
@aricwilliamsdeveloper 2 жыл бұрын
this guy is an incredible teacher
@maiksonstrife
@maiksonstrife Жыл бұрын
This kinda of tutorial should be default, it's the best one.
@GurtMan100
@GurtMan100 2 жыл бұрын
Super useful tutorial! Been trying to get a grip on async for a while now, and this really helped.
@stephenwood4814
@stephenwood4814
This is an excellent video. One nit: you use the word "parallel" early in the video, then again about 14 minutes in. The correct term here would be "concurrent", I believe, since it's important to distinguish between concurrent (single worker thread, async/await) and parallel (multiple worker threads, Threadpool e.g.).
@quicktastic
@quicktastic Жыл бұрын
The key to this being good is in using a simple example. Nice job.
@getsmartpaul
@getsmartpaul 2 жыл бұрын
Thank you for this excellent coding example. It’s educational how you show the most basic first and progress to a more useful example!
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
This video was a great help and a step up in reaching to grasp the concept of this complicated and difficult topic in C#
@raven.4815
@raven.4815 Жыл бұрын
Goddamn, someone that finally explains it in a non flustered way. Thank you so so much!
@NHGeneral
@NHGeneral
I have a program like this:
@Charles_001
@Charles_001
thanks for your vieo it's best one
@siddarthapal2792
@siddarthapal2792
Simple examples to explain with graphics helps. Great work buddy :), god bless
@ahadporkar7355
@ahadporkar7355 2 жыл бұрын
Very Simplified and nice explanation
@alexpato4
@alexpato4
The async keyword DON'T specify that a method is asynchronous, it just starts the state machine for the method. In another words, the async keyword just prepare the method to do some asynchronous stuff.
C# Async Programming - Part 1: Conceptual Background
29:49
Rainer Stropek
Рет қаралды 64 М.
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 110 МЛН
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 20 МЛН
小宇宙竟然尿裤子!#小丑#家庭#搞笑
00:26
家庭搞笑日记
Рет қаралды 16 МЛН
IEnumerable 🆚 IEnumerator Interfaces in C#
34:06
tutorialsEU
Рет қаралды 28 М.
That's NOT How Async And Await Works in .NET!
12:25
Codewrinkles
Рет қаралды 19 М.
Back to Basics: Efficient Async and Await - Filip Ekberg - NDC Oslo 2023
1:01:25
AsyncIO, await, and async - Concurrency in Python
9:12
Socratica
Рет қаралды 87 М.
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 142 М.
C# Async Await Mistakes | Part 1
10:19
Amichai Mantinband
Рет қаралды 32 М.
"Stop Using Async Await in .NET to Save Threads" | Code Cop #018
14:05
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 310 М.
The Async Await Episode I Promised
12:04
Fireship
Рет қаралды 1,1 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 110 МЛН