Async/Await in C# - How it works and how to use it

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.พ. 2025

ความคิดเห็น • 70

  • @ZetwayBROX
    @ZetwayBROX 9 ปีที่แล้ว +21

    Spent a lot of time trying to find material to explain async await to me, but wasn't able to understand anything. You explained how it works, and under 6 minutes! Good job and thanks!

    • @c0deporn
      @c0deporn  9 ปีที่แล้ว +1

      +Zetway Kapinos Awesome, glad it was helpful.

  • @spiralni
    @spiralni 5 ปีที่แล้ว +20

    After a thousand years, I've finally got it!! the best explanation ever.

  • @techcat9312
    @techcat9312 8 ปีที่แล้ว +23

    Good quick explanation on async ops especially for a non-hardcore programmer as like myself. Thanks for sharing the information.

    • @c0deporn
      @c0deporn  8 ปีที่แล้ว +1

      No problem, glad it was helpful.

  • @moherna3323
    @moherna3323 5 ปีที่แล้ว +18

    What a great explanation in record time, very straight and precise is what makes this video great!

  • @xantor94
    @xantor94 7 ปีที่แล้ว +4

    I was always so confused by Async and await and was always very insecure on how to use it. The decompiling was the best explanation I ever saw! Thanks a lot!

  • @wahiduddin7619
    @wahiduddin7619 ปีที่แล้ว

    You’ve made it so clear! Took me so long to find a clear and concise video. Thanks!

  • @mukulpandya616
    @mukulpandya616 5 ปีที่แล้ว +2

    One of the best explanations for async/await!! Great job!

  • @granttapp2875
    @granttapp2875 ปีที่แล้ว

    Went through 3 pages to find something like this! Great video!

  • @mrlildylchillin
    @mrlildylchillin 6 ปีที่แล้ว +1

    This video is brilliant! I really appreciate the depth and clarity you have managed to go into in only 6 minutes. Well done!

  • @lincolnwhite2601
    @lincolnwhite2601 6 ปีที่แล้ว

    I've looking for about 8 hours trying to understand Async/Await on non async methods. Thanks very much for explaining it all and in under 7 minutes! I nearly gave up but luckily found this video

  • @RawCoding
    @RawCoding 5 ปีที่แล้ว +3

    Well done! really good explanation, much prefer the bare bones, to a WPF button example. Special points for the generated code dive

  • @gastos7771
    @gastos7771 9 ปีที่แล้ว +2

    Thanks, much easier to understand than other videos of the same topic, and short at that!

    • @c0deporn
      @c0deporn  9 ปีที่แล้ว +2

      Gas Tos Thanks. If I can explain a complex topic in a few minutes, I'll do it. No need for hours of boring filler.

  • @curryjl1027
    @curryjl1027 9 ปีที่แล้ว

    I am working on understanding what the async and await keywords are doing behind the scenes. This made it a lot clear. Thanks!

  • @aniljain50
    @aniljain50 7 ปีที่แล้ว +1

    The presentation is simply superb and really professional!! Great job!!

  • @bradychristen6865
    @bradychristen6865 5 ปีที่แล้ว +1

    Thank you for your great explaination!! helped me a ton with my current homework!!

  • @arandomambipom9444
    @arandomambipom9444 3 ปีที่แล้ว +1

    so the cost of async/await is the additional memory required for the state machine, i guess? Is that even worth considering?

  • @thethomasproject
    @thethomasproject 5 ปีที่แล้ว

    Agreed, good explanation. Does shed light on the inner workings.

  • @OddStare
    @OddStare 2 ปีที่แล้ว

    Straight to the point thank you

  • @2441979D
    @2441979D 6 ปีที่แล้ว +1

    Async/Await demystified. Presentation is crisp and precise. Subscribed 👍

    • @2441979D
      @2441979D 6 ปีที่แล้ว

      Have you changed the channel name to code insights from codep0rn?

  • @florianrager9631
    @florianrager9631 6 ปีที่แล้ว

    Very nice and quick video. It helped a lot in geting started with async and await.
    Keep up the good work!!

  • @calmsh0t
    @calmsh0t 5 ปีที่แล้ว +1

    So, that means that under the hood async is using an automated multithreading aproach?

  • @robbieboyable
    @robbieboyable 8 ปีที่แล้ว

    Thanks for the explanation, I subbed because many other devs/programmers don't explain as well.

  • @kcvinu
    @kcvinu 5 ปีที่แล้ว +2

    Hi, from where i can get the complete code of this tutorial ?

  • @Piquetures
    @Piquetures 7 ปีที่แล้ว

    Thanks for thie concise and clear explanation! I found the line-by-line break down very helpful!

  • @hk-four-sixteen
    @hk-four-sixteen 3 ปีที่แล้ว

    does await block the next line of code? or does it run together with other tasks?
    lets say I have a code to write two files
    var task1 = Task.Run(async () => await streamWriter1.WriteLine(...........;
    var task1Res = task1.GetAwaiter().GetResult();
    var task2 = Task.Run(async () => await streamWriter2.WriteLine(...........;
    var task2Res = task2.GetAwaiter().GetResult();
    will task2 execute while task1 is running? or will it wait for task1 to complete before it executes?

    • @carll373
      @carll373 3 ปีที่แล้ว +1

      You can use as many await statements you want and they won’t block each other. Create a loop with 5 new awaits and you’ll see them execute at the same time - it’s asynchronous

    • @hk-four-sixteen
      @hk-four-sixteen 3 ปีที่แล้ว

      @@carll373 thanks :)

  • @cepi24
    @cepi24 4 ปีที่แล้ว +1

    Please explain async awaot in js

  • @collinvisser7108
    @collinvisser7108 6 ปีที่แล้ว

    Thanks for the simple video. Helped me a lot

  • @epicmac2708
    @epicmac2708 10 ปีที่แล้ว +1

    Really great and simple explanation

    • @c0deporn
      @c0deporn  10 ปีที่แล้ว

      Thanks!

  • @rarespetrusamartean5433
    @rarespetrusamartean5433 3 ปีที่แล้ว

    await was so confusing because to me at least, it does exactly the OPPOSITE of what I would expect it to...it makes the program NOT wait for the function to finish...you'd think "await" would "await" a result (which happens by default I know) but it does the opposite? wtf

  • @lapincheriatota
    @lapincheriatota 6 ปีที่แล้ว

    Will the async code span a new thread while the rest of your code executes?

  • @rpo3ge
    @rpo3ge 5 ปีที่แล้ว

    yo, huge opening with electric6, insta subscribed

  • @erezlevi8073
    @erezlevi8073 6 ปีที่แล้ว

    Awesome video, very clear.
    Thanks!

  • @mindaugasm3232
    @mindaugasm3232 5 ปีที่แล้ว

    Basically the second thread comes into play from the point/line "await" is added. "async" does not do anything?!..

    • @casinobotscom
      @casinobotscom 5 ปีที่แล้ว

      To my understanding async already creates a state machine and await makes it multithreaded . Can somebody clarify on this?

  • @his-worddevotionals540
    @his-worddevotionals540 5 ปีที่แล้ว

    Awesome man thank you!

  • @angelosolazzo7095
    @angelosolazzo7095 3 ปีที่แล้ว

    It’s not best practice use async void method , Rather you should use async Task if you want return void

  • @Rizkiaqa
    @Rizkiaqa ปีที่แล้ว

    Thanks

  • @markw.schumann297
    @markw.schumann297 4 ปีที่แล้ว +1

    1:20 "Methods marked with async are not asynchronous."
    WHY DID NOBODY TELL ME THIS UNTIL NOW.

    • @arandomambipom9444
      @arandomambipom9444 3 ปีที่แล้ว +1

      lol. probably your coworkers didn't know either xD things like this happen

  • @k-fo9pq
    @k-fo9pq 6 ปีที่แล้ว

    does aync create a new thread or it uses same thread?

    • @hakania
      @hakania 5 ปีที่แล้ว

      Create a new thread.And it does thread works in background

  • @MrIcontrol
    @MrIcontrol 8 ปีที่แล้ว

    Hello ! thanks for the explanation about async methods, i have a little question, i'm coding a kind of puzzle assembler in witch each piece are composed of small other puzzles. i have around 10 algorithm per piece and the main puzzle is around 1.5M piece X24(for sub pieces) i currently got my puzzle solved for 150K pieces per 10 minutes. however i still use sync method. i would like to improve performance and stability by using Async however i couldn't figure out how to implement it with ThreadPool and Task Factory. any tips to do that ?

  • @dieterhaug9742
    @dieterhaug9742 5 ปีที่แล้ว +3

    is this SFW? o.O

  • @nielsgregersen1351
    @nielsgregersen1351 3 ปีที่แล้ว

    No there is no cost, only benefit. You should focus on writing good code instead of worrying about unimportant micro optimizations

  • @basheeral-momani2032
    @basheeral-momani2032 8 ปีที่แล้ว +1

    nice channel name

  • @kavarod101
    @kavarod101 6 ปีที่แล้ว

    nice

  • @gabrielmelendez8685
    @gabrielmelendez8685 10 ปีที่แล้ว +1

    Excelent Video

    • @c0deporn
      @c0deporn  10 ปีที่แล้ว

      Thanks for the feedback.

  • @mikhailcabilao
    @mikhailcabilao 9 ปีที่แล้ว

    Very nice thanks

  • @willgordon5737
    @willgordon5737 5 หลายเดือนก่อน

    What?

  • @barbelljoe
    @barbelljoe 5 ปีที่แล้ว +1

    This is strange porn. My brain hurts and my forearm is not getting any exercise whatsoever.

  • @en_acorn
    @en_acorn 5 ปีที่แล้ว +1

    Well done! better than porn

  • @AtomicCodeX
    @AtomicCodeX 9 หลายเดือนก่อน

    im leaving this video simply cuz he said code porn

  • @xky8124
    @xky8124 5 ปีที่แล้ว

    Cool, but where is the porn?

  • @MrErtghj23
    @MrErtghj23 8 ปีที่แล้ว

    Like and sub for grat expl. THANKS

  • @KentHervey
    @KentHervey ปีที่แล้ว

    thanks