In this video, explore in more detail the principles behind the await and async keywords. Review a "straight talk" definition that is easy to remember if you are asked about it in a technical interview.
- [Instructor] So you just saw how we converted asynchronous program to asynchronous using Async and Await keywords. But how would you explain this if asked in an interview, "What are the purposes for the Async and Await keywords?" Well, let's have what I like to call a Straight Talk. A very straight forward answer would be, Async and Await are essentially markers. They're code markers indicating where code should resume after a task, that is a thread, completes.
Ultimately that is the heart of what we're doing when we're using these two key words to perform asynchronous operations. Now a couple of other points I'd like to add onto this is for you to remember that you generally don't use the Async without Await and vice versa. You don't use Await without Async. They work together, and that's how it was designed. Now something else to mention, is that there's a convention to add Async to the end of the method name. So for example, in our code, if this btnReadFile method is the one we have as Async, it only makes sense to rename it to meet the convention by adding Async.
And when we hit Apply, it should have done the refactoring for us. And now we can go ahead and run our application one more time, make sure everything works as expected. I'll fix this typo here that I just noticed. It's hold your horses, not hold you horse. And Start. And our app still works as expected. Now I wanted to give a straight forward explanation, and that's what I just did.
But to go in a little bit deeper, you can check out this site here in respect to asynchronous programing. But ultimately, it's about eliminating bottlenecks. And as a matter of fact, the first line here says, "You can avoid performance bottlenecks "and enhance the overall responsiveness "of your application by using asynchronous programming." That's what we did. If you scroll down a little bit further, they discuss some of the main areas where it's really ideal to use asynchronous programming.
And one of them you'll notice, they pointed out is using the StreamReader, which is what we did. And as a matter of fact, right below, at the beginning of the first paragraph here, they indicate that it's particularly valuable for applications that access the UI. And that's exactly what our application had an issue with. Our UI was not responsive when we're not using asynchronous programing. But for now, I'd like you to just bookmark this. And circle back when you're done with this course, because it's going to make much more sense, and I don't want you to get buried down into the details before we go through our examples that's going to make this a lot easier to consume.
But now that we've had the opportunity to go through a good review, a nice recap of the concept of Async and Await, let's move on to see it in action in ASP.NET and Entity Framework.
- Converting a desktop app to be asynchronous
- Creating an ASP.Net Core project and model
- Creating a controller
- Converting synchronous code to asynchronous code
- Updating views