Это видео недоступно.
Сожалеем об этом.
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
If you are a C# Developer, I have a Software Testing roadmap designed for you: guiferreira.me/resources/software-testing-roadmap-dotnet
Absolutely enlightening. Thank you. Just subscribed and I'll be back for more.
Thanks Charles! Glad you find it worthy
Thanks, I had not though about that case where you cancel the exception.. very interesting.
Thank you 🙏 That is a tricky one. And since it's rare, it often goes unnoticed
Thanks a lot Gui, you awesome 👍
Thank you 🙏
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.
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!
Love the thumbnail 😂😂😂❤
Captured by the International Space Station 👨🚀
thanks
Boa! Mestre!
Obrigado!
i dont understand on how reloading the page, will effect the previous request and how the cancellation token is passed. can someone explain?
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.
@@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.
@@ardavaztterterian1211 Thanks for the feedback 🙏
I've been trying some new things. Still trying to get it as I want.
Feedback is welcome.
should POST requests also use cancellation token? or is it only for GET requests?
A POST can use it too. Example: If you want to abort a db transaction when a request is cancelled.