C# async, await and Task

Поделиться
HTML-код
  • Опубликовано: 26 авг 2024
  • Coding Tutorial: Just like JavaScript, C# has async and await keywords. Here we explore the similarities and differences between the two languages.
    Source code available here: github.com/Jas...

Комментарии • 11

  • @CodingTutorialsAreGo
    @CodingTutorialsAreGo  4 года назад +1

    Any questions? Do post a comment.
    Source code is available at github.com/JasperKent/CSharpAsyncAndAwait
    And don't forget to subscribe: ruclips.net/channel/UCqWQzlUDdllnLmtgfSgYTCA

  • @AllAboutDataTechnology
    @AllAboutDataTechnology 8 месяцев назад +2

    good video, the example functions show how asynchronous tasks can be used or combined, in different scenarios.

  • @nevaneleven9275
    @nevaneleven9275 3 года назад +3

    You've helped my a decent bit with some more intermediate and/or advanced programming stuff, and I'm learning more and more daily through my own practice as well as free resources provided by many people across the internet including you. If I could make one suggestion though it would certainly be a new mic.

  • @olegsuprun7590
    @olegsuprun7590 3 года назад +2

    I was working on a winforms app recently, was trying to re-create a state machine from on of your videos(pelican) , but a different idea. The idea was - i set a bomb on the ui, then set TimeOut for 2 seconds, and after 2 seconds an explosion would need to appear in place where a bomb was. So i set an event handler in the TimeOut function to update the ui. But when the handler was triggered, i had an error that i cannot acces the ui from a thread that it was not created on. So after some time investigating, i found out that you need to call Invoke or Begininvoke on the control and pass it a delegate, so that is executes in the same thread as ui :)) Anyway great video.

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 года назад

      There are a couple of things to watch out for here.
      The first is that there are various kinds of Timer in .NET. It sounds like your using either System.Timers.Timer or System.Threading.Timer. These both call their timeout immediately in a different thread.
      Easier to use is System.Windows.Forms.Timer, which calls the timeout from the event loop on the main thread, so doesn't need any thread safety code.
      Secondly, even if you do go for a threaded timer, using Invoke is a bit out-of-date. Using async/await is easier. See: ruclips.net/video/_eQ3jfM6zNE/видео.html

  • @bioanu
    @bioanu Год назад +1

    Thank you for the valuable information shared in this video. Although technologies like WPF/WinForms are older topics, they are still used on an extensive scale, so it would be interesting to have a small series about how we approach modern asynchronous methods in WPF and how they can be combined with technologies like SignalR.

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  Год назад +1

      I'll put it on the list, but also, have a look at ruclips.net/video/5d6YoHuSvoI/видео.html

    • @bioanu
      @bioanu Год назад +1

      @@CodingTutorialsAreGoSure! I love your channel and learn a lot from it!! It could be interesting to have a simple mechanism but complete enough for example to test the connectivity of clients to a SignalR hub. I do not want to click a button to connect to the hub but to do this automatically, when WPF starts. There is no example how to determine how many clients are at a specific time connected to a hub. Also, if there are no clients connected to a hub some functions of the hub to be automatically canceled. Thank you!

  • @ivanvincent7534
    @ivanvincent7534 3 года назад +1

    Thanks for the in-depth explanation. One question.. when is it useful to use the ConfigureAwait method?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 года назад

      I have to say, I've never had the need to use it, but then I tend to write applications, whereas it's only really useful when writing frameworks. There's a good (if lengthy) explanation here: devblogs.microsoft.com/dotnet/configureawait-faq/