Тёмный

🔥 How to use CancellationToken in ASP.NET Core WebApi 

Saeed Esmaeelinejad
Подписаться 2,2 тыс.
Просмотров 8 тыс.
50% 1

In this video, I covered all possible ways to use CancellationToken in ASP.NET Core WebApi.
Github repo:
github.com/sa-es-ir/Cancellat...
#dotnet #aspnetcore #asyncawait #asynchronous #cancellation
Moments:
00:00 - Intro
01:14 - Check the code base
02:14 - Api without CancellationToken
04:30 - Using CancellationTokenSource object
07:02 - Using Request CancellationToken
09:05 - Who creates the HttpContext object?
12:36 - Using CancellationToken in EF Core
18:53 - Closing
--------------------------------------------------
======FOLLOW ME=========
LinkedIn Profile:
/ sa-es-ir
Github:
github.com/sa-es-ir

Опубликовано:

 

21 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 35   
@fabrizziocht
@fabrizziocht 9 месяцев назад
Great explanation, thank you!
@sa-es-ir
@sa-es-ir 9 месяцев назад
Glad you like it
@saddamhossaindotnet
@saddamhossaindotnet 10 месяцев назад
I am very excited man! Already Subscribed. :)
@sa-es-ir
@sa-es-ir 10 месяцев назад
Awesome! Thank you!
@aaa-pt7lm
@aaa-pt7lm 9 месяцев назад
Really good work and valueable share 👍👍
@sa-es-ir
@sa-es-ir 9 месяцев назад
Glad you like it
@rahulsinghishere
@rahulsinghishere 7 месяцев назад
Very Informative, Thanks
@sa-es-ir
@sa-es-ir 7 месяцев назад
Glad you like it 🌷
@TellaTrix
@TellaTrix 3 месяца назад
Wow, Amazing content Saeed. I know what the main problem in my organization project. I have poorly managed all resources. I am going to fix them soon.
@sa-es-ir
@sa-es-ir 3 месяца назад
Best of luck with new fixes, hope it will boost your app, Thanks
@Arasaik
@Arasaik 9 месяцев назад
Hey Saeed, This video was so helpful. Keep going. Please create a video on how to make an asynchronous HttpRequest.
@sa-es-ir
@sa-es-ir 9 месяцев назад
Thanks for the feedback, sure I'll do
@rezakamrani4440
@rezakamrani4440 9 месяцев назад
Just Keep Going!
@sa-es-ir
@sa-es-ir 9 месяцев назад
Thanks Kamrani jun❤️
@thecodeman_
@thecodeman_ 10 месяцев назад
Keep going!
@sa-es-ir
@sa-es-ir 10 месяцев назад
Thank you Stefan, I'll do❤
@rezabayat9222
@rezabayat9222 9 месяцев назад
great Saeed. there is one missing part: when to use CancellationToken.None. sometimes we have multiple operations, in which all of them accept cancellationToken; but after specific operation we should not cancel the process. for example: var transfer = service1.GetTransfer(cancellationToken); service2.DoTransfer(transfer, someArgs, cancellationToken); service3.TransferApplied(transer, CancellationToken.None); if we pass the cancellationToken to the third service, if the request is cancelled, we would have an inconsistent state. sometimes we should pass CancellationToken.None, if we want that our code continues running, even if the request is cancelled by the user , timeout, etc.
@sa-es-ir
@sa-es-ir 9 месяцев назад
Great input Reza and totally agree, actually it depends on sepecfic requirements but in such cases for keeping task running maybe we don't need to use CancellationToken at all.
@rezabayat9222
@rezabayat9222 9 месяцев назад
You are completely right. But there ist one problem: when you do not pass the cancellation token parameter, other programmers may see warnings or later on want to improve the code and add the cancellation token. So to avoid such cases, we can pass the None, to say that it was a known issue.
@heribertodejesusdejesus8316
@heribertodejesusdejesus8316 10 месяцев назад
Muchas gracias por la aportación, me has dado mejor visión del uso adecuado del CancellationToken, será interesante ponerlo en práctica. Por otro lado, en el video muestras el ejemplo de la capa de repositorio por EF, sin embargo, si el escenario fuera que para esta capa la comunicación es por StoreProcedures donde para "delete, insert o update " manejan sus propias transacciones, ¿sería recomendable el uso del CancellationToken?
@sa-es-ir
@sa-es-ir 10 месяцев назад
It's recommended to use CancellationToken if the method accept it, usually all methods that has "Async" postfix they accept it. In case of stored procedure it's the same and CancellationToken should used as well as it will be cancelled on database
@heribertodejesusdejesus8316
@heribertodejesusdejesus8316 9 месяцев назад
Agradezco tu tiempo y pronta respuesta, ya me suscribí a tu canal, excelente día.
@shreypaidhungat6280
@shreypaidhungat6280 10 месяцев назад
Subscribed :)
@sa-es-ir
@sa-es-ir 10 месяцев назад
Thank you🌷
@muttBunch
@muttBunch 7 месяцев назад
Saeed, this is awesome. Thank you. Is there anyway to send a cancellation via another endpoint to cancel? I made a live log monitor which runs a while loop looking for !token.IsCancellationRequested, but when it’s running, I’d like to send like a stop parameter to it from another action result. It’s cool that we have Swagger, Postman, etc but in a real world app, obviously the user won’t be interfacing with either of those. Thanks.
@sa-es-ir
@sa-es-ir 7 месяцев назад
Happy you like it. About the question, the CancellationToken in automatically createe by webServer (Kestrel) so doesn't make sense to CancellationToken to another request and won't work but if the purpose is only cancelling the second request you can disconnect or abort that request (so the other side will be cancelled)
@JohnSmith-yr7ih
@JohnSmith-yr7ih 10 месяцев назад
Please zoom your IDE, it is difficult to watch with phone, and please provide code, direct link of project for every tutorial.
@sa-es-ir
@sa-es-ir 10 месяцев назад
Appreciate for the feedback, very true, I try to keep them in mind for the next video
@smc_onetwo
@smc_onetwo 4 месяца назад
should we be using the cancellation token on POST and UPDATE requests?
@sa-es-ir
@sa-es-ir 4 месяца назад
Yes everywhere! For Post or update requests, its more important to use CancellationToken because in any exceptions those changes can be rolled back.
@ishfaqbabar1192
@ishfaqbabar1192 7 месяцев назад
Will it work only on webServer (Kestrel) or it will also work on Out-of-process hosting (IIS) or In-process hosting (IIS)?
@sa-es-ir
@sa-es-ir 7 месяцев назад
Works with all webservers including IIS as well.
@cleitoncarlospereira2006
@cleitoncarlospereira2006 9 месяцев назад
Hey Saeed, This video was so helpful. Keep going. Please create a video on how to make an asynchronous HttpRequest.
@sa-es-ir
@sa-es-ir 9 месяцев назад
Very glad you like it, Sure it's on my list, stay tuned :)
Далее
Cancellation Token in .NET | Exploring C# and DOTNET
18:42
Cancellation Culture
27:09
Просмотров 3,1 тыс.
Concurrent Hosted Service in .NET 8 | .NET Conf 2023
31:12
5 Rules For DTOs
17:56
Просмотров 39 тыс.
💥 gRPC on .NET: How to use gRPC in ASP.NET Core Api
25:05
Getting Started with OpenTelemetry in .NET
19:56
Просмотров 52 тыс.
Learn GraphQL In 40 Minutes
39:43
Просмотров 733 тыс.
How to use CancellationToken in ASP.NET C# API
5:33