No video

C# Async/Await/Task Explained (Deep Dive)

  Рет қаралды 402,741

Raw Coding

Raw Coding

Күн бұрын

In this tutorial we conver the asynchronous programming style in C# we take a deep diving looking at the state machine that the async keyword spawns. How the await keyword creates checkpoints in the state machine. And how the Task class allows us to bridge our code to use the asynchronous programming model.
Source: github.com/T0s...
Patreon 🤝 / raw_coding
Courses 📚 learning.raw-c...
Shop 🛒 shop.raw-codin...
Discord 💬 / discord
Twitter 📣 / anton_t0shik
Twitch 🎥 / raw_coding
👉 Try Rider
www.jetbrains....
RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP
Videos
Karel Zikmund • Async demystified - Ka...
Jeffrey Richter • LTS Webinar “Performin...
Jeffrey Richter (with Demo at 41:55) • Performing Asynchronou...
Adam Krieger (Good info on Thread Pool) • Stealing Time with the...
Articles
devblogs.micro...
www.codeprojec...
ranjeet.dev/un...
#csharp #async #dotnet

Пікірлер: 790
@rheinelroimanalo7321
@rheinelroimanalo7321 Жыл бұрын
Thank you programming Jesus!
@RawCoding
@RawCoding Жыл бұрын
Stay blessed son
@sonikajha3788
@sonikajha3788 6 ай бұрын
😂
@dattabansode6598
@dattabansode6598 3 жыл бұрын
misunderstanding is extremely common. Many people are taught that multithreading and asynchrony are the same thing, but they are not. Example. You are cooking in a restaurant. An order comes in for eggs and toast. Synchronous: you cook the eggs, then you cook the toast. Asynchronous, single threaded: you start the eggs cooking and set a timer. You start the toast cooking, and set a timer. While they are both cooking, you clean the kitchen. When the timers go off you take the eggs off the heat and the toast out of the toaster and serve them. Asynchronous, multithreaded: you hire two more cooks, one to cook eggs and one to cook toast. Now you have the problem of coordinating the cooks so that they do not conflict with each other in the kitchen when sharing resources. And you have to pay them. Now does it make sense that multithreading is only one kind of asynchrony? Threading is about workers; asynchrony is about tasks. In multithreaded workflows you assign tasks to workers. In asynchronous single-threaded workflows you have a graph of tasks where some tasks depend on the results of others; as each task completes it invokes the code that schedules the next task that can run, given the results of the just-completed task. But you (hopefully) only need one worker to perform all the tasks, not one worker per task.
@RawCoding
@RawCoding 3 жыл бұрын
Can you explain to me what made you think I'm misunderstanding something? To me it seems you explained what I explained but from a high level, which is what everyone does, and at no time did I make the following claim: > that multithreading and asynchrony are the same thing, but they are not. My explanation is based around - handing off a task to something else to work on, so in your example it would be a fryer (external process) frying an egg (working on a task), and we are not waiting for it (thread isn't blocked). When I go to explain that a different thread may complete the rest of our task it's like chef1 starting to cook an egg and chef 2 finishes it. If you are just giving another high level overview of asynchrony there are ton's of these, people are still looking for these videos because they want to understand the abstraction behind it. And I'll re-state I do think your explanation is correct and informative but doesn't cut where it needs to.
@exogendesign4582
@exogendesign4582 3 жыл бұрын
Should've have find this comment sooner, I should learn both though. What I want was Synchronous for my project Since it depends on the completion of the first task before the next. that's why I there is no blocking in my app, since im using async, it really baffles me but this comment really made me see the difference, and the video made me understand how to right the code, good combination. Thanks for sharing your knowledge Datta Bansode. and Raw Coding you guys rock.
@emreaka3965
@emreaka3965 2 жыл бұрын
@@RawCoding You said, "another thread is indeed going to complete the boiling process." but the man says "there is no another thread. it runs single thread." If I am wrong, please correct.
@user-xh1du2uw6y
@user-xh1du2uw6y 2 жыл бұрын
​@@emreaka3965 I think that the number of threads depends on operation type we need to execute (IO-bound or CPU-bound). IO-bound operations don't need additional threads, they use some external devices that don't need our help. But I might be wrong
@ZombieMagnum
@ZombieMagnum 2 жыл бұрын
As I understand it from this video, the use of async/await DOES in fact sometimes automatically create additional threads, hoewever not necessarily for every async function or await statement. It is confusing that people insist that async/await is ''single-threaded asynchrony" when in practice it is not true. I do understand that multi-threading is a different concept, your explanation is great.
@pratikzirpe315
@pratikzirpe315 3 жыл бұрын
I haven’t seen anyone else explain such complex concept with such ease and still thorough - to the point. Thank you 🙏🏻
@RawCoding
@RawCoding 3 жыл бұрын
Cheers!
@PaulSebastianM
@PaulSebastianM 3 жыл бұрын
@@RawCoding 5:53 Cheers! 😆
@aronhegedus
@aronhegedus 3 ай бұрын
this is really useful because you're showing us the inbetween code, rather than just telling us. I find that that's usually the most instructive, because I can then go and check that as well
@ragtop63
@ragtop63 7 ай бұрын
Although I already had a pretty good understanding of how all this works, I have to say that your explanation is by far the best that I’ve seen. Too many times other videos show you some simple implementation that really can’t be ported to the real complexities of asynchronous programming. So you leave those videos with a “Hmm, ok. I guess that makes sense. But how do I apply it to my specific situation?” kind of feeling. What you’ve done here is not given us the fish but instead taught us how to fish. A fundamental understanding of complex topics is always the best method. Great job!
@TJahmusick
@TJahmusick 3 жыл бұрын
This is exactly how I wanted this explained to me. Incredible! Thanks!
@RawCoding
@RawCoding 3 жыл бұрын
Thank you for watching))
@spuriustadius5034
@spuriustadius5034 4 жыл бұрын
I got totally confused about Dump() and Dump(string s) until I realized that you are using some kind of built in extension method that your IDE (linqpad?) somehow defines for you. Once I understood that, it was super clear.
@RawCoding
@RawCoding 4 жыл бұрын
Awesome! glad it didn't get in the way too much :) Yeah linqpad is like a mini development environment, as you can see I get to run my code instantly instead of waiting for the app to compile/start etc... and the data vizualisation that you get through Dump can be pretty incredible :)
@nobytes2
@nobytes2 3 жыл бұрын
pretty weird tbh, just use console write like every other human 🙄
@RawCoding
@RawCoding 3 жыл бұрын
No
@Jwhite1979
@Jwhite1979 3 жыл бұрын
100% this! I'm 1:49 into the video, and I pull out C# In A Nutshell, find nothing, Google "String dump method", find nothing, search through KZbin comments for someone, for the love of god, anyone explaining what the hell this .Dump method is all about! Thank you Spurius. Today, you're the hero.
@RichardONeil
@RichardONeil 3 жыл бұрын
@@RawCoding agreed...Linqpad is the greatest tool on my belt to quickly work things out. You get all the cruft out of the way and can hone directly in on an algorithm that you are trying to build, or understand. I highly recommend buying it to everybody that does this for a living.
@aleksandermirowsky7988
@aleksandermirowsky7988 Жыл бұрын
Rust's async/await functionality operates in a similar way, as it also expands into a state machine. It has been explained by Rust experts multiple times, but your explanation takes it to another level. The ability to visualize the intermediate generated code is just the icing on the cake. Great stuff, happy to see that you're still an actively posting on KZbin. Instantly subscribed and activated notifications.
@RawCoding
@RawCoding Жыл бұрын
Thank you really appreciate it!
@hsnnoznn
@hsnnoznn 11 ай бұрын
Man, I usually take the information I need and close the video but you are absolute legend. I can not skip without a huge thanks. You explained it very well. Again, thanks a lot.
@user-yc9rp8mv5b
@user-yc9rp8mv5b 10 ай бұрын
Dear friend. Visit youtube channel "Solve My Programming Task". They create simple programs for free. I used it. I am a student.
@mikecu2249
@mikecu2249 2 жыл бұрын
This must be the Best Explanation about this Topic on our Planet! You didnt not only manage to create a crystal clear image, approch and explanation. You also picked the confused C# Devs up who still tried to figure out, what the clock is happening to my code? Thank you!
@RawCoding
@RawCoding 2 жыл бұрын
Glad I could help!
@MiningMozo
@MiningMozo 3 жыл бұрын
Step 1 - Complete High school Step 2 - Complete Colleges The next step is to figure out what the fuck is going on
@RawCoding
@RawCoding 3 жыл бұрын
Pretty much :P
@michalbrndiar5317
@michalbrndiar5317 4 жыл бұрын
Crystal clear and absolutely the best explanation of this concept I've ever seen. Keep up great work! :)
@RawCoding
@RawCoding 4 жыл бұрын
Thank you )
@WantOxide
@WantOxide 3 жыл бұрын
Bullshit this crap is not clear
@michalbrndiar5317
@michalbrndiar5317 3 жыл бұрын
Hmm, probably it is not this video's fault. 🤔
@WantOxide
@WantOxide 3 жыл бұрын
@@michalbrndiar5317 of course it is. there are more clear videos, so it's clearly his video fault
@WantOxide
@WantOxide 3 жыл бұрын
@@michalbrndiar5317 And if it's not his video's fault it means you just do spaghetti code as he does (and spaghetti explanations)
@speakoutloud7293
@speakoutloud7293 4 жыл бұрын
Man, I just can't get enough of your videos. You rock with this! Keep it up.
@RawCoding
@RawCoding 4 жыл бұрын
Cheers, glad you liked them
@pieDesert
@pieDesert 2 жыл бұрын
S-Tier explanation and demonstration. It is so difficult to find decent tutorials out there, but this one was no fat just cut right to the information I needed to hear and delivered with such simplicity. Also actually using the full time of the video to teach and explain and not self promote and advertise. Appreciate the raw commentary!
@RawCoding
@RawCoding 2 жыл бұрын
Glad I could help)
@emrealtuntas1319
@emrealtuntas1319 2 жыл бұрын
After 05:51 i directly clicked like button.
@RawCoding
@RawCoding 2 жыл бұрын
Hehe
@nipungrover7058
@nipungrover7058 10 ай бұрын
Legend has it that you understand programming better when jesus teaches you himself. Amen.
@Esurnir
@Esurnir 2 жыл бұрын
Thank you for clearing up this absolute swamp of complexity that is async await in c#
@RawCoding
@RawCoding 2 жыл бұрын
Thank you for watching))
@cuzsleepisthecousinofdeath
@cuzsleepisthecousinofdeath 2 жыл бұрын
Finally a person who's just like Jamie King(pardon me for making a comparison): straight to the point, showing the internal guts of things Subscribed instantly
@RawCoding
@RawCoding 2 жыл бұрын
Cheers
@StreetBladerBloke
@StreetBladerBloke 3 жыл бұрын
Very clear and especially deep dive which is always a missing part in programming videos, you have nailed it.. thanks and keep it up with these videos they are pure gold..maybe u can create a course and sell it..I am sure deep dives are missing in today's programming world where instructors are just bothered about creame only but not the cake. You and Jamie king are the only ones who are taking it to another level. Thanks for ur efforts
@RawCoding
@RawCoding 3 жыл бұрын
Cheers, there will be a course at one point
@LarrySmith1437
@LarrySmith1437 3 жыл бұрын
Well done, sir. I struggled with how to present this topic to my dev department, your example helped a lot.
@RawCoding
@RawCoding 3 жыл бұрын
Cheers
@TheFeaz
@TheFeaz 3 жыл бұрын
Hey man, this (and your other video showing HOW to use async / await) was REALLY good information. Another person said it, but I'll say it again, this was the best presentation of this material that I've ever seen. I'm a senior software engineer with my company, and I've been here almost 20 years. Most of my work is in hard-core business logic, and I haven't done a lot with system-level stuff, multi-threading, and all that. With the changing system model these days and an emphasis on micro-services, I'm re-visiting these concepts (that and I'm doing some of my own private consulting now, doing web development, Docker containers, etc. and certainly am seeing a lot of this async stuff, particularly in the bakc-channel OAuth stuff.) Anyway, the biggest challenge I have learning this stuff in a meaningful way is that content out here usually goes one of two places-- It either shows very simplistic "hello world" type examples, that make would make a great "Await / Async 101" course or a college lab project, but in practice they don't scale well to anything resembling what we would actually DO in an enterprise application. On the other hand, there are task-oriented "how-to's" that show you the how but not the WHY. I really appreciated your deep-dive into this and a look at how the MSIIL implements this. That really gave a whole new dimension to my understanding of how this stuff actually works under the covers, and gives me some much-needed insight into how I could leverage these features in our enterprise applications.
@RawCoding
@RawCoding 3 жыл бұрын
Thank you for your comment))
@jasonherrera7605
@jasonherrera7605 3 жыл бұрын
Thank you, it is difficult for me to follow your English, but it has been the best explanation I have ever known.
@RawCoding
@RawCoding 3 жыл бұрын
Awesome, thank you )
@magerehenk7579
@magerehenk7579 3 жыл бұрын
why is it difficult to follow his english?
@RawCoding
@RawCoding 3 жыл бұрын
I’m not a native speaker and some other people aren’t ether, so it’s a compounding effect
@ehsanhadid1260
@ehsanhadid1260 3 жыл бұрын
Just wow, I want to go back, leave University and just follow you.
@RawCoding
@RawCoding 3 жыл бұрын
Haha don’t do that :P
@investmentjourney7912
@investmentjourney7912 3 жыл бұрын
Best explanation till now, not just showing windows form for ui activeness like others. 👍
@RawCoding
@RawCoding 3 жыл бұрын
Cheers
@lefrutit228
@lefrutit228 2 жыл бұрын
tutorials such that are exaclty what youtube needs lol, I barely can find tutorials that I cant understand from the first watching, they're too simple, but this is excellent, thank you!!
@RawCoding
@RawCoding 2 жыл бұрын
Thank you 🙏
@geerivana
@geerivana 3 жыл бұрын
Your videos are way better than any other official online courses
@RawCoding
@RawCoding 3 жыл бұрын
Cheers
@forbin80
@forbin80 4 жыл бұрын
Bruhhhh... I've been reading about and even using async for a couple years now and in 20 mins you just cleared up everything I didn't understand about the way this stuff works. All the weirdness I've seen in my code now makes perfect sense. Fantastic video, I can't thank you enough. By far the most clear explanation of async/await I've ever seen.
@RawCoding
@RawCoding 4 жыл бұрын
Thank you, glad I could help:)
@zhh174
@zhh174 4 жыл бұрын
thank you so much. no one explained it on youtube. they just show the use of async and await.
@RawCoding
@RawCoding 4 жыл бұрын
Cheers, that’s what my problem with all the tutorials were :)
@razortier4284
@razortier4284 Жыл бұрын
Great job. Not so many guys are explaining how it works under the hood with state machine
@gotham4u
@gotham4u 2 жыл бұрын
Wow, I understood it finally . I was trying to understand async and await keywords for last an hour, but "yield" was not comprehensible. Thanks very much.
@RawCoding
@RawCoding 2 жыл бұрын
Cheers, I have a video about IEnumerable and yield you can have a look
@rafiul41
@rafiul41 11 ай бұрын
One of the most underrated channels on KZbin.
@Time_Leak
@Time_Leak 4 жыл бұрын
Thanks for the clear explanation. It was really helpful to see IL that is responsible for all the magic.
@RawCoding
@RawCoding 4 жыл бұрын
Cheers)
@hlazunov
@hlazunov 2 жыл бұрын
This is the insane video about async/await in .NET. I have never seen a better explanation of async in .NET. Thanks a lot.
@AjitGoel
@AjitGoel 2 жыл бұрын
This is a amazing video, first clear explanation of the async-await internals. Thank you Raw Coding.
@RawCoding
@RawCoding 2 жыл бұрын
Thank you for watching
@rmcgraw7943
@rmcgraw7943 3 ай бұрын
I have a good idea for a video…Consider this…you have a UI, a service layer, a business layer, a data services layer, and a data store layer. Should you, or would you, have async methods that awaited each subsequent layer, or would you have a UI layer that had async methods/controllers (so you could await calls to the service layer and/or business layer), and would those subsequent down tier calls also be LABELed as async methods, themselves having calls to deeper layers that it awaited…OR, would you have async UI Methods that awaited down tier(business layer) calls to methods (that were not LABELed async [the keyword]) that simply returned Task. That is to ask, would you chain down tiers like Async UI awaits Async Service that awaits aync Business that awaits async Data, etc, or would you have Async (to enabled await) UI that awaited Task returning Service that called Task returning Business, etc? TRUST ME, it MATTERS ALOT! The labeling of methods as async that have no await in them has a non-negligible cost in context switching and state persistence, not to mention the garbage collection involved in cleaning all those state machine allocations.
@marketfinds
@marketfinds 2 жыл бұрын
Excellent work, glad you went down into the IL Code. Helps make it clearer what magic is going on.
@RawCoding
@RawCoding 2 жыл бұрын
Glad you liked it!
@kopilkaiser8991
@kopilkaiser8991 2 жыл бұрын
Thank you so much for taking the time to explain it. I have understood some of the concepts and I will need to rewatch it to better grasp the concepts. But still I was completely lost with this asynchronous programming, and was able to find some of the way by watching your tutorial. Thank you for simplifying the complex concepts. It takes a great mind to decode the entanglement which the async await Task brings in when you jump into it after being comfortable with synchronous programming. I will keep on digging into this until it is drilled deep into my mind.
@user-yc9rp8mv5b
@user-yc9rp8mv5b 10 ай бұрын
Dear friend. Visit youtube channel "Solve My Programming Task". They create simple programs for free. I used it. I am a student.
@martinrogachevsky5627
@martinrogachevsky5627 Жыл бұрын
One of the best explanations so far, great examples, thanks a lot! Only one thing didn't let me go through this on the first attempt is when you were explaining what network device is doing with the thread on your 'art', you said that it "frees" the thread. For someone who is not native speaker that sounded a lot like "freeze" the thread and really confused me for some time. So just be aware of these little verbal things but in general very helpful and worth sharing!
@RawCoding
@RawCoding Жыл бұрын
Thank you, yeah I’m not a native speaker so might mess up some pronouncements
@ghazanfarabbas4187
@ghazanfarabbas4187 4 жыл бұрын
Never seen such a insightful video before. Keep it up man...
@RawCoding
@RawCoding 4 жыл бұрын
Thanks
@_Ming_Ming_
@_Ming_Ming_ 2 жыл бұрын
Thank you for this clear explaination sir! for this I will never skip ads in your video
@RawCoding
@RawCoding 2 жыл бұрын
thank you
@abhirammadhu2973
@abhirammadhu2973 Жыл бұрын
You didn't add sugar😒 BTW, this is the best video explaining async/await in C#. You're right. All other video just simply explains how to implement asynchronous program rather than explaining what exactly happens under the hood.
@RawCoding
@RawCoding Жыл бұрын
thank you
@dunefedaykiin
@dunefedaykiin 4 жыл бұрын
Awesome video, like always! Looking forward to the next video about the practical use of async/await!
@RawCoding
@RawCoding 4 жыл бұрын
Cheers ))
@iedi3
@iedi3 6 ай бұрын
very impressive quality, and the relaxed atmosphere just perfect for some cigarettes and a beer (even though i stopped both), plus a reggae music in the background
@phongs2nhu
@phongs2nhu 3 жыл бұрын
Good job, man. I'm from Viet Nam. So by watching your video, I studied new knowledge and English language. Of course, your voice is great with nice intensity. Thanks a million.
@RawCoding
@RawCoding 3 жыл бұрын
Glad I could help :)
@armandopenaleonett1258
@armandopenaleonett1258 3 жыл бұрын
Thank you I have always had problems understanding this now it's way more clear!
@RawCoding
@RawCoding 3 жыл бұрын
Awesome 👏
@oganovdavid
@oganovdavid 3 жыл бұрын
Thanks so much for sharing your knowledge. Haven't met anyone explaining this better than you. I've finally got some understanding of what's going on. Subscribed
@RawCoding
@RawCoding 3 жыл бұрын
Cheers, glad I could help :)
@Hypermommy
@Hypermommy 3 жыл бұрын
Thank you for this very clear explanation of a sometimes confusing concept.
@RawCoding
@RawCoding 3 жыл бұрын
Thank you for watching
@stevenstone307
@stevenstone307 2 жыл бұрын
Awesome explanation mate. Funnily enough another thing I learnt in this video is that you can put underscores in big numbers lol
@RawCoding
@RawCoding 2 жыл бұрын
Double whammy!
@xieweiling7543
@xieweiling7543 3 жыл бұрын
The last part - the state machine is interesting!
@RawCoding
@RawCoding 3 жыл бұрын
sure is!
@vaya99
@vaya99 Жыл бұрын
Best explanation for async await 👍, looking for deep dive for .ConfigureAwait() function. Keep it up ... how my computer is expecting it and how to read a code sequence is best part with respect to state sequence explanation.
@RawCoding
@RawCoding Жыл бұрын
Glad I could help )
@rowanlidbury
@rowanlidbury 3 жыл бұрын
How have I not found you before.? You need to investigate why you don't show up cos this is gold.
@RawCoding
@RawCoding 3 жыл бұрын
Thank you)
@user-qy4zo8qn4i
@user-qy4zo8qn4i Жыл бұрын
Awesome video! Just what I was looking for. Also while I was diving into the Task code I had noticed a TaskStatus enum at the top. Immediately I was thinking that there must be some state machine at work happening here. So thanks for confirming that.
@owiz9212
@owiz9212 4 жыл бұрын
Thanks very much Anton! Really simplifies asynchronous processing. Much appreciated!!
@RawCoding
@RawCoding 4 жыл бұрын
Thank you for watching
@kasra7885
@kasra7885 4 жыл бұрын
You left no questions. And a good rhythm
@RawCoding
@RawCoding 4 жыл бұрын
That’s what we like :D
@sreekanthbharatham7577
@sreekanthbharatham7577 4 жыл бұрын
Simple and very useful explanation of context switching. Never seen anyone put it together like this. For a long time I was aware the await takes control back to caller making it do other stuff. But never could grasp how potentially another thread picks up the context to continue from where it left off. That realization and looking at different thread ids in different blocks made a world of difference in my understanding. Simply outstanding !! Thank you
@RawCoding
@RawCoding 4 жыл бұрын
Glad I could help:)
@martinnicolas1399
@martinnicolas1399 4 жыл бұрын
Finally, I understand what is happening! Thanks
@RawCoding
@RawCoding 4 жыл бұрын
That is awesome
@anpham871
@anpham871 4 жыл бұрын
Thanks a lot!! You motivated me so much!! You are the best C# developer i've ever seen on youtube.
@RawCoding
@RawCoding 4 жыл бұрын
Cheers ma dud ))
@BryantCobarrubias
@BryantCobarrubias 2 жыл бұрын
You're a very good teacher.
@RawCoding
@RawCoding 2 жыл бұрын
Thank you
@elkhoukhi
@elkhoukhi 4 жыл бұрын
Man I just came across your channel, quality material! I subscribed, Keep up the good work
@RawCoding
@RawCoding 4 жыл бұрын
Thank you, hope you like the rest :)
@BradenJohnYoung
@BradenJohnYoung 9 ай бұрын
Finally, a good freaking explanation. Thank you!
@onnuttig
@onnuttig 3 жыл бұрын
Finally just a simple example of how this shit works, thanks man, instant sub
@RawCoding
@RawCoding 3 жыл бұрын
Glad you like it )
@mrwillis5339
@mrwillis5339 4 жыл бұрын
Useful to hear a concise explanation .
@RawCoding
@RawCoding 4 жыл бұрын
Glad I could help
@jimsteinPeerless
@jimsteinPeerless 4 жыл бұрын
You do overemphasize the importance of threads like everyone trying to explain Async does. It is a nice very demo but (this is not covered by this video) if you in the first example replace the await Task.Delay(300) with a busy loop (the same as in the main function) there will not be another thread spawn and everything will execute on a single Thread. This is task concurrency on a single thread(?). Task.Delay is not CPU bound but the busy loop is CPU bound. So Task.Delay is good for simulating an IO bound Task and therefore you get continuation on another thread. The threads are operating on a layer below concurrency, so you do not need to have multiple threads to have Task concurrency(?). Kind regards
@RawCoding
@RawCoding 4 жыл бұрын
Thank you for sharing
@mrcalico7091
@mrcalico7091 4 жыл бұрын
@@RawCoding Thankfully, You're the teacher here!
@matthewkeron1448
@matthewkeron1448 4 жыл бұрын
schooooled him
@user-hp9zq3jn7s
@user-hp9zq3jn7s 3 жыл бұрын
Can someone please explain me what Jimstein Peerless meant? As he said, i replaced "await Task.Delay(300)" with CPU bounded task (the loop shown in the video for example): await Task.Run(() => { var a = 0; for (int i = 0; i < 100_000_000; i++) { a += i; } Console.WriteLine("CPU-bound task in running on ThreadId = " + Thread.CurrentThread.ManagedThreadId); }); And i still see it being executed on another thread (Console.WriteLine shows thread id different from the main thread id). OR did he meant not using async/await and just start a raw CPU bound loop? But then it would be totally synchronous program and it is not the point of this video. But he still got so many likes on his comment. So seems like people found it useful. I am so confused...
@RawCoding
@RawCoding 3 жыл бұрын
I guess I haven’t explained the Task.Run in this video where it’s literally a task you give the thread pool to execute, if you have a Synchronous Task method that returns a task without having async await , it will literally wait for the function to finish executing to give you the result of a Task object, like a normal function you are just waiting for the return value.
@StevenBloomfield
@StevenBloomfield 4 жыл бұрын
Always wondered what all the MoveNext calls were in aggregate exception stack traces. I see now where they come from. Thanks!
@RawCoding
@RawCoding 4 жыл бұрын
Glad I could help
@BorisMiljkovic
@BorisMiljkovic 2 жыл бұрын
Finally, a good explanation. Thank you!
@RawCoding
@RawCoding 2 жыл бұрын
Glad you enjoyed it!
@tomaszwitkowski9545
@tomaszwitkowski9545 3 жыл бұрын
I am in the fifth minute and I got understood it more than I had understood after the classes
@RawCoding
@RawCoding 3 жыл бұрын
Hope you find the rest just as useful)
@ehsaneftekhari4525
@ehsaneftekhari4525 Жыл бұрын
Thanks a lot. that was the best explanation of how async actually works 🙇‍♂🙇‍♂🙇‍♂🙇‍♂🙇‍♂. now, I can sleep
@ievheniiierokhin1677
@ievheniiierokhin1677 4 жыл бұрын
Good way to explore what really happens behind the scene with ilspy
@RawCoding
@RawCoding 4 жыл бұрын
Cheers
@ldohlj1
@ldohlj1 3 жыл бұрын
Wow! Great analogy and great explanation. Thank you
@RawCoding
@RawCoding 3 жыл бұрын
Thank you for watching
@dishantchourasia4513
@dishantchourasia4513 2 ай бұрын
Awesome explanation! Please keep up the good work
@AC-fs2rl
@AC-fs2rl Жыл бұрын
This is the thing I was looking for, thank you
@RawCoding
@RawCoding Жыл бұрын
Glad I could help!
@stardrake691
@stardrake691 8 ай бұрын
Awesome explanation, I’ve always thought that async-await in C# acts like the one in Javascript, but there are differences.
@thatguywiththeface9463
@thatguywiththeface9463 2 жыл бұрын
Very detailed and well explained tutorial. Thank you, coding Jesus!
@RawCoding
@RawCoding 2 жыл бұрын
Haha thank you
@matthewsheeran
@matthewsheeran 4 жыл бұрын
Very good explanation. I too am going to look with ILSpy to see the non-async code which is generated which helps to see the calls to turn async code back into sync! ;-) So basically asyc/await does nothing more or less than build the state machine for you on your behalf. Also its async/await all the way up and down.
@RawCoding
@RawCoding 4 жыл бұрын
Yes )
@rajenlenka7806
@rajenlenka7806 3 жыл бұрын
God bless you ..May you live a 100 years
@RawCoding
@RawCoding 3 жыл бұрын
Thank my brother
@MetaArcher
@MetaArcher 4 жыл бұрын
Pretty cool and clear video. One of the best async videos I've seen. Hope next time you do a deep dive to compare Parallelism and Async
@RawCoding
@RawCoding 4 жыл бұрын
Thanks, as I’ve shown in this video it’s pretty much parallel already )
@user-li9jq7iw6r
@user-li9jq7iw6r 2 жыл бұрын
Best explanation i've ever seen. Thanks!
@RawCoding
@RawCoding 2 жыл бұрын
Ty
@koenfrontatie
@koenfrontatie 6 ай бұрын
really appreciate your style of teaching! you've helped me lots
@sankaralingammuthusamy6142
@sankaralingammuthusamy6142 Жыл бұрын
It was really superb explanation about async and await. Thanks bro keep up the good work
@Voloshhka
@Voloshhka 8 ай бұрын
Literally turned on this video while making a cup of tea😅
@kadirfurkancaybas580
@kadirfurkancaybas580 Жыл бұрын
The best explanation ever.
@loam
@loam 2 жыл бұрын
23:36 Second second, heh, nice language metamorphosis, I noticed that thing myself couple weeks ago while ruminating in English, and now It pop ups in the video)
@RawCoding
@RawCoding 2 жыл бұрын
hehe )
@CCV334
@CCV334 2 жыл бұрын
Love the explanation! Would love to see a video on the basics of LINQPad. I can intuit how Dump(); works but would love to see your take on what's possible with the software.
@RawCoding
@RawCoding 2 жыл бұрын
Linkpad has a tutorial built in that does it
@tylergoffinet1085
@tylergoffinet1085 4 жыл бұрын
Great personifications and IL code walkthroughs! Thanks!
@RawCoding
@RawCoding 4 жыл бұрын
Cheers
@user-yt8cf6zw1i
@user-yt8cf6zw1i Жыл бұрын
Wonderful explanation!
@RawCoding
@RawCoding Жыл бұрын
thank you
@lucaspedroso3351
@lucaspedroso3351 3 жыл бұрын
Man, thank you for making it simple
@RawCoding
@RawCoding 3 жыл бұрын
Thank you for watching)
@arunkutube
@arunkutube 3 жыл бұрын
love it, thanks for explaining using ILSpy, it makes things clear.
@RawCoding
@RawCoding 3 жыл бұрын
Glad you like it
@yv989c
@yv989c 4 жыл бұрын
Continuation if the word you are looking for 🙂. Great video.
@RawCoding
@RawCoding 4 жыл бұрын
Cheers )
@emmanuelmotsi
@emmanuelmotsi Жыл бұрын
Such a great explanation. Learn a lot from the DEEP DIVE! Thanks!
@jwange1
@jwange1 3 жыл бұрын
Oh man! you really have a good head in clarifying things. thank you. Besides, what kind of editor do you use? interesting!
@RawCoding
@RawCoding 3 жыл бұрын
Rider and LinqPad
@alexplom5958
@alexplom5958 3 жыл бұрын
Absolutely phenomenal video
@RawCoding
@RawCoding 3 жыл бұрын
Cheers)
@abuzeromohammed3386
@abuzeromohammed3386 4 жыл бұрын
You hit important topics thanks
@RawCoding
@RawCoding 4 жыл бұрын
Thank you )
@rafaspimenta
@rafaspimenta Жыл бұрын
I really love to see how debug threads and async codes to find bugs in parallel tasks
@KrishnaList
@KrishnaList 4 жыл бұрын
Very Nice Explanation Anton It is really Deep Dive
@RawCoding
@RawCoding 4 жыл бұрын
Thanks )
@tweakmy
@tweakmy 4 жыл бұрын
I was looking good material for async and I didn't have time to sit on other material. Yours is the best to understand within minutes.
@RawCoding
@RawCoding 4 жыл бұрын
Awesome!
@antropovp
@antropovp Жыл бұрын
My favorite .NET youtuber
@noxagonal
@noxagonal 2 жыл бұрын
Small summary for C++ people. Functionality vise "Task" is very similar to "std::future". "async" is similar to "std::async" except that the function itself is defined asynchronous instead of calling any function asynchronously. To get the same behaviour in C++ as in C# you could make a function that calls another function with "std::async" and returns "std::future" Implementation vise they're of course very different.
@drillerboyyt4027
@drillerboyyt4027 Жыл бұрын
I am so happy I found his channel.
@COLAMAroro
@COLAMAroro 4 жыл бұрын
Really nice tutorial ! Easy to understand, goes into detail and cuts when there are silence, so the video doesn't get too long Quick tips, on LINQPad, you have `Util.OpenILSpy()` built-in, no need to build a project on the side to see what's inside 😉
@RawCoding
@RawCoding 4 жыл бұрын
Thank you!!
@TheJAGreaper
@TheJAGreaper 4 жыл бұрын
I think the part you mentioned about the task executing on another thread is not technically correct especially considering the lack of the use of .ConfigureAwait(false). The whole concept of multi-threaded programming is entirely separate to the async programming model being that the async programming model is an abstraction for parallelism. It could be running on another thread, it might not, the default behaviour of the synchronisation context will resume the task on the same thread unless .ConfigureAwait(false) is specified. The exception to the rule, of course, being ASP.NET Core which uses a thread pool instead of the default behaviour of the synchronisation context.
@RawCoding
@RawCoding 4 жыл бұрын
I don’t say the task is ran on another thread, the task may be completed by a different thread.
@TheJAGreaper
@TheJAGreaper 4 жыл бұрын
@@RawCoding 7:00 - 7:05
@RawCoding
@RawCoding 4 жыл бұрын
I see, yes you are correct, I’ve said it runs in parallel, which is not 100% correct, it runs synchronously up until await and then goes in to the big loop and a different thread completes the task. So there is a degree of parallelism but isn’t ran in parallel
@TheJAGreaper
@TheJAGreaper 4 жыл бұрын
​@@RawCoding Well no a different thread doesn't necessarily complete your task in parallel because you haven't told the synchronisation context to allow the task to run somewhere other than the captured context with .ConfigureAwait(false), Thus if the current synchronisation context only has access to one thread the exact same thread executes the code when it is freed up by the await call you to make with the Task.Delay method. This is especially dangerous when you are working with STAThread frameworks like WPF because the SyncronisationContext for the UI thread only has access to the UI thread making it incredibly easy to create deadlocks when working with WPF if you're not using .ConfigureAwait(false). (You can read more about it here from Microsoft themselves devblogs.microsoft.com/dotnet/configureawait-faq/ ) Asynchronous programming with tasks can be parallel and they can be multi-threaded but they are no inherently so, what they are is an abstraction for thread management, not parallelism and multi-threading. You can have an entire application the uses async programming but only ever has one thread (not that you would want that). So when you explain it as if it is based around threading and parallelism you are passing on a very dangerous misunderstanding that will bite developers in the ass when they encounter these cases.
@RawCoding
@RawCoding 4 жыл бұрын
I know it doesn’t necessarily complete the task, the example that I showed in the video I specifically show that the thread is working in the loop while the task completes. The exception is a WPF app where there is a UI thread that you need to sync with. Also thank you for sharing the valuable information.
How to use Async/Await/Task in C#
29:45
Raw Coding
Рет қаралды 75 М.
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 90 МЛН
Semaphore Explained C#
12:24
Raw Coding
Рет қаралды 40 М.
Why I Don't Like Singletons
29:05
The Cherno
Рет қаралды 58 М.
That's NOT How Async And Await Works in .NET!
12:25
Codewrinkles
Рет қаралды 21 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 169 М.
The Async Await Episode I Promised
12:04
Fireship
Рет қаралды 1,1 МЛН
Settling the Biggest Await Async Debate in .NET
14:47
Nick Chapsas
Рет қаралды 143 М.
What are ASYNC and AWAIT in C#? Asynchronous Programming Tutorial
18:34
8 await async mistakes that you SHOULD avoid in .NET
21:13
Nick Chapsas
Рет қаралды 312 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,5 МЛН
C# Async Programming - Part 1: Conceptual Background
29:49
Rainer Stropek
Рет қаралды 64 М.