Configuring Await

Ғылым және технология

The C# await keyword lets you pick up where you left off after an asynchronous call. But did you know you can select which thread you'll be running on?
Source code available at: github.com/JasperKent/Async-Context
Topics include:
- Different threading models for Console, Web and UI apps
- Thread safety in WPF and WinForms
- Using async and await
- Managing threads with Task.ConfigureAwait
- Improving responsiveness

Пікірлер: 38

  • @conlethmackle4062
    @conlethmackle40622 ай бұрын

    Best explanation yet on this topic I've seen

  • @xopabyteh
    @xopabyteh8 ай бұрын

    What a lovely, professional, but most important: what a useful video. Thank you, more people should know about this.

  • @CodingTutorialsAreGo
    @CodingTutorialsAreGo Жыл бұрын

    Want more on async/await? Let me know. Source code available at: github.com/JasperKent/Async-Context Remember to subscribe at kzread.info/dron/qWQzlUDdllnLmtgfSgYTCA.html And if you liked the video, click the 👍.

  • @przemosz7337
    @przemosz7337 Жыл бұрын

    As always a beautiful and easy explanation. Documentation has much more complicated, this simple example shows what it's all about. Thanks! Edit: What's more my co-worker says we will be using this on monday (We have some problems with our WPF app). I didn't know how this works but now i feel that i have this knowledge. Brilliant timing! Thanks again!

  • @activex7327
    @activex7327 Жыл бұрын

    NOTE: Console apps and Web apps may behave differently when it comes to what thread runs after the await. An MVC app uses Synchronization context for the await. When the await returns, you return back to the original thread that initiated the async operation. This is also true for WebForm applications. Therefore, it can be summarized, the thread that will run after await will depend if the application has specific Synchronization context. The synchronization context then is used to select the right thread to run after await completes. UI apps: Return back to the UI thread MVC/Webform apps: Return back to the thread that made the original request Console: Use available thread from the thread pool

  • @GELSAV777

    @GELSAV777

    13 күн бұрын

    thank you for note

  • @bioanu
    @bioanu Жыл бұрын

    Excellent excellent excellent! Exactly what I need!! Leaving aside the main theme, I discovered the local method. I didn't even know this concept exists! Thank you!!

  • @seekersofwisdom85
    @seekersofwisdom85 Жыл бұрын

    I love your videos. I'm surprised how come u have less views. One suggestion anyways, a little better voice (clear mic) will really help

  • @badboydessert
    @badboydessert Жыл бұрын

    Definitely best tutorial. Keep filming tutorials.

  • @finwwwfinwww4669
    @finwwwfinwww46693 ай бұрын

    best explanation ....

  • @sandrakyoutube
    @sandrakyoutube Жыл бұрын

    Excellent! Very helpful. Easily followed along. It all made sense to me. Yay. Thank you very much. 😃

  • @peternguyen9382
    @peternguyen9382 Жыл бұрын

    I dont know how to say Thanks to you Sir!!!

  • @ISKernel
    @ISKernel2 ай бұрын

    Very nice video !! I would love to see more. Just for clarification, it is quite difficult to follow from where "ReportThread" is called while looking at the output. Could you add maybe do something like: void ReportCall([CallerMemberName]string methodName = null, [CallerLineNumber]int lineNumber = -1) { Console.WriteLine($"Thread ID: {Thread.Id} at {methodName} line {lineNumber}"); } That would make is easier (at least for me) to follow.

  • @dhkhewaz4244
    @dhkhewaz4244 Жыл бұрын

    Thanks for the video, very helpful and well explained. Off to make so soft

  • @imikhan83
    @imikhan83 Жыл бұрын

    Very informative thanks... 👏

  • @ukpachalla
    @ukpachalla Жыл бұрын

    Nicely Explained

  • @shooob
    @shooob Жыл бұрын

    Thanks for the explanation. I read about ConfigureAwait() in a book but didn't completely understand it and the .Net Docs aren't very helpful. I have been using at the "end of the line" as the book recommended (basically, the last "async" call you make in that process, eg. an async query to a database or an HTTP request like in your example) but the book didn't mention it for UI usability. I wonder if there's a use case where it would be beneficial to use ConfigureAwait() for non-GUI apps, like Console or Web APIs. Is there a scenario where we would want to return control back to the Main thread in those apps? Thanks again for the video!

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    Жыл бұрын

    It only makes sense in application types which have a thing called a SynchronizationContext. Otherwise, the behaviour is always the equivalent of ConfigureAwait(false). UI apps do have a SynchronizationContext, but console apps don't. In ASP.NET, it's more confusing. Framework apps do, Core apps don't. blog.stephencleary.com/2017/03/aspnetcore-synchronization-context.html

  • @shooob

    @shooob

    Жыл бұрын

    @@CodingTutorialsAreGo Thanks for the reply & clarification. Makes sense to me. I hope having it in there even though it's not needed won't be detrimental to performance (or do I have a lot of refactoring to do? 😁).

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    Жыл бұрын

    @@shooob As ever with performance, the answer is 'suck it and see'. That said, the recommendation in the article I link is to use it in libraries where you don't know what kind of app you're actually in, so I guess the performance hit isn't significant.

  • @shooob

    @shooob

    Жыл бұрын

    @@CodingTutorialsAreGo Great advice. These are in reusable libraries so they *could* be used in a GUI app I suppose; unlikely, but I'll just leave it in there and say I planned ahead all along. haha.

  • @sky-soft-2024
    @sky-soft-20243 ай бұрын

    eng\Jasper... I want to ask a question? I heard someone say that asynchronous programming does not create multiple threads, and that it only uses one thread. I see here that a new thread other than the main thread has been created, and I trust you to answer this question. My sincere regards to you.😊

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    3 ай бұрын

    The await and async keywords to not of themselves create threads. The await keyword is applied to a Task and waits until that Task is complete. In many cases, that Task may be running code in a separate thread, but not always. For example, if the Task caches a result, it may run in a separate thread the first time to get the data, but not subsequent times when it simply returns the cached result. It's worth noting that in JavaScript things are very different, and we don't have separate threads when using async/await.

  • @Tarodev
    @Tarodev Жыл бұрын

    Your videos are so damn good. I just plugged you (again) in my discord server.

  • @wahabshahid3760
    @wahabshahid3760 Жыл бұрын

    sotNice tutorialng either - I assu that works with Edison too) and I never thought about after that. Now, at tNice tutorials mont, I am inspired! I am

  • @ajohna2522
    @ajohna2522 Жыл бұрын

    THANK YOU!! ✌

  • @henry-js
    @henry-js Жыл бұрын

    Thank you for the video! God save the king!

  • @UnseenScofield
    @UnseenScofield9 ай бұрын

    So we can seperate UI logics vs Thread logics backend can serve us a data with async method and ui can await it with configureawait true

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    9 ай бұрын

    That's right.

  • @charlyg.campos1600
    @charlyg.campos16008 ай бұрын

    hello Jasper, it will be nice when you refer to another video if you place the link somewhere. thanks

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    8 ай бұрын

    The links should appear in the top righthand corner of the video. Sorry if I've missed any.

  • @DongoBongKong
    @DongoBongKong Жыл бұрын

    Have you considered authoring Pluralsight courses? You are really good!

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    Жыл бұрын

    I'll wait till they ask me.

  • @jageshkoiri8990
    @jageshkoiri8990 Жыл бұрын

    But there is a fix i found

  • @ghaiath-altrabulsi
    @ghaiath-altrabulsi Жыл бұрын

    Thanks, could you please cover Task.FromResult?

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    Жыл бұрын

    I'll put it on the list.

  • @CodingTutorialsAreGo

    @CodingTutorialsAreGo

    Жыл бұрын

    That's there now: kzread.info/dash/bejne/dJp105STmcipcrQ.html

  • @ghaiath-altrabulsi

    @ghaiath-altrabulsi

    Жыл бұрын

    Thanks a lot. 🙂