How to use CancellationToken in ASP.NET C# API

  Рет қаралды 6,513

Gui Ferreira

Gui Ferreira

Күн бұрын

Пікірлер: 20
@gui.ferreira
@gui.ferreira Жыл бұрын
If you are a C# Developer, I have a Software Testing roadmap designed for you: guiferreira.me/resources/software-testing-roadmap-dotnet
@charlesopuoro5295
@charlesopuoro5295 7 ай бұрын
Absolutely enlightening. Thank you. Just subscribed and I'll be back for more.
@gui.ferreira
@gui.ferreira 7 ай бұрын
Thanks Charles! Glad you find it worthy
@andreasbrunnstrom8458
@andreasbrunnstrom8458 Жыл бұрын
Thanks, I had not though about that case where you cancel the exception.. very interesting.
@gui.ferreira
@gui.ferreira Жыл бұрын
Thank you 🙏 That is a tricky one. And since it's rare, it often goes unnoticed
@GarethDoherty1985
@GarethDoherty1985 Жыл бұрын
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 Жыл бұрын
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!
@Tamer_Ali
@Tamer_Ali Жыл бұрын
Thanks a lot Gui, you awesome 👍
@gui.ferreira
@gui.ferreira Жыл бұрын
Thank you 🙏
@vivekkaushik9508
@vivekkaushik9508 Жыл бұрын
Love the thumbnail 😂😂😂❤
@gui.ferreira
@gui.ferreira Жыл бұрын
Captured by the International Space Station 👨‍🚀
@alefsilva2541
@alefsilva2541 Жыл бұрын
Boa! Mestre!
@gui.ferreira
@gui.ferreira Жыл бұрын
Obrigado!
@ardavaztterterian1211
@ardavaztterterian1211 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
​@@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 Жыл бұрын
@@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 11 ай бұрын
should POST requests also use cancellation token? or is it only for GET requests?
@gui.ferreira
@gui.ferreira 11 ай бұрын
A POST can use it too. Example: If you want to abort a db transaction when a request is cancelled.
@wisamidris
@wisamidris Жыл бұрын
thanks
Building Complex Objects in a Simple Way with C#
12:19
Gui Ferreira
Рет қаралды 10 М.
Don't Use Polly in .NET Directly. Use this instead!
14:58
Nick Chapsas
Рет қаралды 75 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
How to Organize Your ASP.NET Program.cs File
15:40
Gui Ferreira
Рет қаралды 6 М.
Building better DTOs in C#
11:57
Gui Ferreira
Рет қаралды 7 М.
What is OpenTelemetry?
12:55
Highlight
Рет қаралды 18 М.
The Secret HttpClient Feature You Need To Use in .NET
10:41
Nick Chapsas
Рет қаралды 75 М.
Netflix Removed React?
20:36
Theo - t3․gg
Рет қаралды 61 М.
How to Integration Test with the new .NET Testing Framework
20:39
Gui Ferreira
Рет қаралды 1,1 М.
Secure Your .NET API in 15 Minutes: JWT Authentication Tutorial
15:05
Milan Jovanović
Рет қаралды 28 М.
Your code Knows too much!
5:12
Gui Ferreira
Рет қаралды 6 М.
Make Your API Requests INSANELY Fast in .NET
9:30
Nick Chapsas
Рет қаралды 51 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН