Это видео недоступно.
Сожалеем об этом.

How to use CancellationToken in ASP.NET C# API

Поделиться
HTML-код
  • Опубликовано: 8 янв 2024
  • I saved my web API database with C# CancellationTokens.
    💎 Be a Patreon to get the source code: / gsferreira
    🚨 KEY LINKS
    🤝 Support me on Patreon (and get access to source code) here: / gsferreira
    💌 Free Developer Insights: guiferreira.me...
    🔗 GET IN TOUCH
    LinkedIn: / gferreira
    Twitter: / gsferreira
    GitHub: github.com/gsf...
    Get my newsletters: guiferreira.me...
    Visit my blog: gsferreira.com
    👋 WHO AM I
    Hey! If you're new to my Channel, I'm Guilherme. Call me Gui. I'm a Minimalist Software Craftsman. What do I do here? I share tips on how to simplify your life as a Developer.
    🎵 MUSIC CREDITS
    Healing Salve / StreamBeats / Lofi
    #dotnet #csharp

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

  • @gui.ferreira
    @gui.ferreira  7 месяцев назад

    If you are a C# Developer, I have a Software Testing roadmap designed for you: guiferreira.me/resources/software-testing-roadmap-dotnet

  • @charlesopuoro5295
    @charlesopuoro5295 2 месяца назад +1

    Absolutely enlightening. Thank you. Just subscribed and I'll be back for more.

    • @gui.ferreira
      @gui.ferreira  2 месяца назад

      Thanks Charles! Glad you find it worthy

  • @andreasbrunnstrom8458
    @andreasbrunnstrom8458 7 месяцев назад +1

    Thanks, I had not though about that case where you cancel the exception.. very interesting.

    • @gui.ferreira
      @gui.ferreira  7 месяцев назад

      Thank you 🙏 That is a tricky one. And since it's rare, it often goes unnoticed

  • @Tamer_Ali
    @Tamer_Ali 7 месяцев назад +2

    Thanks a lot Gui, you awesome 👍

  • @GarethDoherty1985
    @GarethDoherty1985 7 месяцев назад +2

    Does this work exactly the same on a SPA application. I build Web Client Apps using Blazor. I am on a page and press a button to send an API call to the server to get data (lets say its long running) and when I navigate to another page, that Request to the API isn't cancelled, and I assume that's because there wasn't a browser "refresh" that happened.
    So in a SPA situation where request cancellations don't happen between page navigations, how would you make the request cancel if you navigate to a different page.
    I notice that when users load my app, they land on the Dashboard page which makes a lot of calls to the API to get data from the DB to populate charts etc. But they very quickly navigate to another page in the Blazor App, before the request finish and charts are rendered etc, but all those API calls from the Client to the API continue anyway.

    • @gui.ferreira
      @gui.ferreira  7 месяцев назад

      That's a brilliant question!
      I'm not a Blazor expert, but that makes sense to me. In a SPA, in fact, there's no reason to "automatically" cancel the request.
      But, I think this is what you are looking for: steven-giesel.com/blogPost/69051bce-81b6-410c-9b9e-c2a0f1c88371
      Combine the article with the content of this video, and it should work!

  • @vivekkaushik9508
    @vivekkaushik9508 7 месяцев назад +1

    Love the thumbnail 😂😂😂❤

    • @gui.ferreira
      @gui.ferreira  7 месяцев назад

      Captured by the International Space Station 👨‍🚀

  • @wisamidris
    @wisamidris 7 месяцев назад +2

    thanks

  • @alefsilva2541
    @alefsilva2541 7 месяцев назад +1

    Boa! Mestre!

  • @ardavaztterterian1211
    @ardavaztterterian1211 7 месяцев назад +1

    i dont understand on how reloading the page, will effect the previous request and how the cancellation token is passed. can someone explain?

    • @gui.ferreira
      @gui.ferreira  7 месяцев назад

      On a F5 the connection of the ongoing HTTP request will stop and start a new one. The web server will know that. Then, asp.net will let you know that through the form of a cancellation token that the first request was cancelled.

    • @ardavaztterterian1211
      @ardavaztterterian1211 7 месяцев назад

      ​@@gui.ferreira I like your content, but I wish you showed that in action. instead we got a 5 minute lecture with slides. Programming shouldn't be done like that.

    • @gui.ferreira
      @gui.ferreira  7 месяцев назад

      @@ardavaztterterian1211 Thanks for the feedback 🙏
      I've been trying some new things. Still trying to get it as I want.
      Feedback is welcome.

  • @thanzeeljalaldeen
    @thanzeeljalaldeen 7 месяцев назад +1

    should POST requests also use cancellation token? or is it only for GET requests?

    • @gui.ferreira
      @gui.ferreira  7 месяцев назад +1

      A POST can use it too. Example: If you want to abort a db transaction when a request is cancelled.