async await c#|async await for beginners

preview_player
Показать описание

async await c# - await async keywords are used to write asynchronous programming in c#. async await in .net core is a vast topic and in this video I tried to explain it in easiest way possible to help beginners understand async await concept in c# better. async await concept in c# is a complex topic, however it is easier to write async await programs in c# as most of the complexity lies in c# Task objects.

In operating system there will be two kinds of threads. CPU bound threads and background threads. CPU bound threads are limited and expensive to create and background threads are cheap threads. we can use async await in c# when you are performing any operations which includes I/O, Network calls etc.

When c# async await program runs, if there is any blocking operation like I/O, Db calls etc, It delegates that particular piece of code to a cheaper background thread and main thread returns back to the pool or it may do other tasks. This enables asynchronous programming in c#. It is not true that, if we use async await in c#, it always creates a new thread and performs the processing. The task will be delegated to a background thread only when there is a blocking operation like I/O or db calls etc.

async marks the method as asynchronous and enables the awaitable feature of the method. We may or may not use await in async method. If we dont use await in async method, the main thread will not wait for the background thread to complete. If we use async await in .net core when the task is being delegated from main thread to child thread, it sends the context of the task. This is called as context switching.

Once the background thread completes the task asynchronously, if the main thread is in await it returns back the response to the thread. It is not like the background thread always returns the context back to the original thread which delegated the task. Background thread can return the response back to any of which is free.

using async await in .Net , it improves the performance a lot as the task is shared among multiple threads using async await constructs. This is the main advantages of async await. async await concept in c# may yield different results in different machines as it all depends on the system processor, number of cores the system has etc.

Chapters
00:00 async await c# introduction
00:23 async await in Pizza Shop
01:45 understanding async await concept of .Net
04:00 async await in c# program

#async_await#
#asyncawait_Net
#asyncawaitInC#

Рекомендации по теме
Комментарии
Автор

Neat explanation, wish you will be doing more of core concepts like these.

karthiks