C# Async / Await – Make your app more responsive and faster with asynchronous programming

50
2



Asynchronous programming can be intimidating. What’s even worse is when you think you learned how to do something and then you try it in your application and it doesn’t work. This video is an attempt to fix all of that. In it, you will see how to use the async and await keywords to make your user interface more responsive and to speed up your code’s operation. You will also see how to turn an existing method from being synchronous to asynchronous. Along the way, we will cover best practices and how to make sure our application behaves like we expect after we make a part of it asynchronous.

Newsletter signup (with exclusive discounts): (your email will be kept safe and you will not be spammed).
Source Code:

Nguồn:https://wijstaanvooronzegrondrechten.org/

50 COMMENTS

  1. can I ask you a quick question?
    I have this method that i want to make asynchronous. It simply supposed to take an array of strings, and then create a List of strings with the same content, but just with something apended to every string

    private async static Task<List<string>> ParTest(string[] thisstringlist)
    {

    List<string> returnList = new List<string>();

    for (int i = 0; i < thisstringlist.Length-1; ++i)
    {
    Task.Run(() => returnList .Add(thisstringlist[i] + "pluuus this"));
    }

    return returnList;
    }
    I really cant figure out what i should put as awaiting here, maybe the return?

    Im really struggling with this, I really hope someone can give me a tip

  2. I wonder if microsoft copies these ideas from ECMAScript 6 of javascript from browsers, or if they copy them from microsoft. Promise, async await, Promise.all([array_here]) anyone? And I like javascript's syntax for this better. Just by placing async after the access modifier, javascript already knows this is gonna return a Promise, so I could do private async void myMethod(){} without any problems, without using the exception mentioned.

  3. Nice video! i do have one question though 🙂 isnt downloading something a little bit of a bad example?, since there a so many other factors that could make a download slow or fast?

    And again thanks a lot for this video, its really good

  4. Why return type must be Task even tho i am not gonna await it? Could you elaborate on that? Is it affecting performance or something?

  5. Great session. Do you think using async with Dapper could be an appropriate tool for running asynchronous SQL Server operations? Apparently it's possible (if hacky) in SSMS but – other software solutions aside – sounds like C# async may be a simpler method. I'm imagining something like transferring data from one set of SQL tables to another set, where the order of completion of the insert statements doesn't matter, so all could be run asynchronously.

  6. For those who wondering about MVVM, I have been using ReactivUI, it is just amazing…Makes it easy, so easy. The documentation is little bit hard to debug but trust me it is worth it. will make your life a lot easier. try it.

  7. Quck thought regarding WPF/MMVVM. With MVVM i figured if I put code in code behind that works only for that view. for example this.DragView, or quick calculation of marigins etc. will keep ViewModel cleaner and it's still separated. previously I found myself introducing partial viewmodel class files, that in my opinion did too much. Just a thought regarding keeping view completely clean.

  8. that's a great video about asyn await , only one thing we can add in this is exception handling , but apart from that its giving the perfect picture.

  9. Awesome. I was wondering if you had a video on asynch and turns out you do. Do you ever talk about how to use it within the context of ajax and jquery? Say in an MVC application.

  10. Awesome video. But i have an issue with what am working on currently.

    Can this also increase the speed of pushing a large amount of data into the database using Entity Framework core? I'm currently facing that issue at the moment, looking at the best way to resolve this, trying to map each userId to another user of a record close to 12k records. But it takes forever and doesn't end. Any help on this?

  11. Very good explanation on using async and await. It would be nice if you can create a video explaining how threading evolved from eap, apm to task based.
    Thanks

  12. OK. Why didn't you put ReportWebsiteInfo also into lambda expression after calling Downloadwebsite?

    What would happen if i call GUI related functions (which executes ONLY in main thread) in winform app?

  13. Like the videos a lot Tim. One thing I noticed is that sometimes you're saying something interesting and then speed up a lot as you finish the statement, making it hard to hear what you said.

    For instance @26:05 you begin to say something about your preference between using an array or a list to return results and you quickly say the beginning of the statement, then slow down a lot on the easier to understand part, then really quickly end the statement too, like "nowimMoreofaFan of a list, rather than an array, because, forEachStillworksonThem". I understood it the third time I listened to it, lol

  14. I wonder if these videos would benefit from having some quiet and upbeat background music? I've seen some other tech trainers using background music in tutorials and I feel like it contributed a sense of energy and intertia to the video 🙂

  15. You are funny. Async void completely okay using events. Make a video more related to reality using commands as an example.

  16. Thanks, Tim, this was REALLY helpful. I just used this to tweak my program in which I needed to make around 200 API requests to a server and this trimmed the time down from around 33 seconds on average to under 3 seconds!
    As an extra bonus, I was able to have the task (request) be an object property, where I have a list of ~200 of said objects and then use:
    await Task.WhenAll(mods.Select(m => m.request));
    Super slick!

  17. I am senior .NET developer and I still use your tutorials and love watching you. One can never know enough. You are really awesome teacher and this tutorial on async/await is just what I needed. I know it is something what we are supposed to use, but not really have any real knowledge on WHY exactly. So awesome, especially with parallel.

  18. Hi Tim, to me both methods doing exactly the same. You still awaiting for all tasks by using – await Task.WhenAll(tasks) – it's exactly the same as await Task.Run . I do not understand why it's faster.

  19. What's the running time of doing synchronous but not reporting, instead saving simply to another list, then printing? Wouldn't it be the same as the async saving it to the list of task then printing?

LEAVE A REPLY

Please enter your comment!
Please enter your name here