No video

Cancellation Token in .NET | Exploring C# and DOTNET

  Рет қаралды 4,899

Rahul Nath

Rahul Nath

Күн бұрын

Hey 👋 Imagine having a long-running request triggered by a user on your server. But, the user is no longer interested in the result and has navigated away from the page.
However, the server is still processing that request and utilizing resources until you come along and implement Cancellation Tokens in the application code.
.NET uses Cancellation Token for cooperative cancellation of asynchronous or long-running synchronous operations.
So let’s learn more about Cancellation Token and save some of that server compute time.
I will show you the problem of unnecessarily spending server resources on no longer required processes and how to solve them using Cancellation Tokens.
We will see an example of using Cancellation tokens in a console application, in a long-running HTTP API Endpoint, and when making external calls to API Endpoints. I will use Amazon S3 to show how you can use Cancellation Tokens to cancel from uploading large documents when they are no longer required.
Thank you to AWS for sponsoring this video.
🔗 Blog - www.rahulpnath.com/blog/cance...
🔗 Code - github.com/rahulpnath/youtube...
00:00 Introduction
00:44 The Problem
03:22 What is Cancellation Token
04:48 Cancellation Token Demo
08:12 Passing Cancellation Tokens
10:09 Listening to Cancellation Requests
10:32 Cancellation Token In API
13:30 Cancellation Token and HTTP API Calls
13:54 AWS S3 Storage
18:05 Should you always Cancel?
Additional Watching
📹C# Series - bit.ly/mycsharp
📹 ASP Series - bit.ly/asp-net-core-series
📹Azure Series - bit.ly/azure-series
📹AWS Series - bit.ly/aws-net-series
📹RabbitMQ Series - bit.ly/rabbitmq-net-series
Come say hi! ✋
🎙️Uses - www.rahulpnath.com/uses
🌍Blog - www.rahulpnath.com/
✉ Subscribe to my Newsletter - www.rahulpnath.com/subscribe
🐦Twitter - / rahulpnath
📸Instagram - / rahulpnath
#dotnet #csharp

Пікірлер: 38
@daStitches
@daStitches 4 ай бұрын
I would be interested in seeing some of those other patterns you were talking about for handling cancellation tokens!
@RahulNath
@RahulNath 4 ай бұрын
Thank you Ralph. Adding this to my list!! Glad you liked this.
@ChosenHandle
@ChosenHandle 4 ай бұрын
Your channel is a gem. Really clear delivery of concepts with coherent and easy to follow examples. Thanks for the upload.
@RahulNath
@RahulNath 3 ай бұрын
Glad you think so!
@sureshp34
@sureshp34 4 ай бұрын
Thanks for posting this video, I was requested to post the the cancellation token video a long back ago. This video will helps me to implement in my project. Thanks a lot.
@RahulNath
@RahulNath 4 ай бұрын
Glad it was helpful Suresh! Do let me know if you have any other suggestions.
@arjunanselvam
@arjunanselvam 4 ай бұрын
Thanks a lot Rahul. I was reading this topic yesterday. Now you have upload video for the same. I am also watching your aws videos. It is really fantastic.
@RahulNath
@RahulNath 4 ай бұрын
Glad you like it Arjun! Do let me know if you have any suggestions or feedback
@akashkarve1991
@akashkarve1991 4 ай бұрын
Nice video and very well explained. Would like you to request to create more videos on cancellation token. Cheers !!!
@m3coo
@m3coo 4 ай бұрын
Very helpful! Thanks a lot Rahul
@RahulNath
@RahulNath 4 ай бұрын
Most welcome Faisal!
@sreekumar7875
@sreekumar7875 4 ай бұрын
Superb Video, glad you made this type of useful contents
@kj2w
@kj2w 4 ай бұрын
Yay!!! New Rahul Nath content!!
@RahulNath
@RahulNath 4 ай бұрын
Thank you for your support!!
@susantasahoo3457
@susantasahoo3457 4 ай бұрын
Great learning video,thank you..can you please share git path also?
@RahulNath
@RahulNath 4 ай бұрын
Glad you liked it Susanta - Code is available here github.com/rahulpnath/youtube-samples/tree/main/cancellation-token-example
@abuzeromohammed3386
@abuzeromohammed3386 4 ай бұрын
You are great Sir thank you
@RahulNath
@RahulNath 4 ай бұрын
So nice of you - thank you ! And you call me Rahul 😀Do let me know if you have any topic suggestions or feedback
@abuzeromohammed3386
@abuzeromohammed3386 4 ай бұрын
​@@RahulNath new advance topic like Mico services and how they communice or for me Identity server 4 or you dive in this topic how user can make searching for example and another button for cancel the searching
@aijazchauhan865
@aijazchauhan865 3 ай бұрын
Please please creaate separte video which covers other methods to cancel the operation. it would be very helpfull to me.
@blueLavender-s7f
@blueLavender-s7f 4 ай бұрын
My ask might be basic, but Could you Please add an Example where UI can call a cancellation as in realtime where we cant capture console.keypress or swagger window closure
@sivasankaransomaskanthan8264
@sivasankaransomaskanthan8264 4 ай бұрын
By "UI" Are you referring to desktop or mobile native UI like WinForms , WPF, UNO or Avalonia UI ?
@rahulgadekar5460
@rahulgadekar5460 4 ай бұрын
Hi Rahul can you please make a tutorial on azure durable functions 😊 Thanks in Advance
@RahulNath
@RahulNath 4 ай бұрын
Thank yo ufor the suggestion Rahul. Yes this is on my list!
@AkashM20
@AkashM20 4 ай бұрын
Hey Rahul, what is the terminal that you are using
@RahulNath
@RahulNath 4 ай бұрын
Windows Terminal - More details here www.rahulpnath.com/blog/setting-up-windows-terminal/
@duanelakoduk561
@duanelakoduk561 Ай бұрын
Great presentation and video series. In the console project, you initiate cancellation using a button press. In the API, you demonstrate cancellation when the browser is closed. Is there a way to implement cancellation from a button click in a .NET UI to cancel the API without closing the browser, or through a refresh action?
@RahulNath
@RahulNath 12 күн бұрын
Thank you! You should be able to use AbortController! I will try and do a video around this topic.
@duanelakoduk561
@duanelakoduk561 10 күн бұрын
@@RahulNath Thanks for the hint, I located the AbortController reference on mdn web docs.
@RahulNath
@RahulNath 10 күн бұрын
@@duanelakoduk561 hope you were able to solve it using that
@RahulNath
@RahulNath 8 күн бұрын
Hey Here's a video I made on that and just published! kzfaq.info/get/bejne/qrl1lpiZvd6VhIE.html
@TellaTrix
@TellaTrix 4 ай бұрын
Does it cancel database operations? if I requested Cancellation Token does it cancel all long running sql query?
@RahulNath
@RahulNath 4 ай бұрын
Yes it does if you pass along the token.
@carlos.maradiaga
@carlos.maradiaga 4 ай бұрын
Excelente, thank you for sharing this topic. Do you have this source code in somewhere to download ?, Thank you.
@RahulNath
@RahulNath 4 ай бұрын
Glad you liked it Carlos. Yes the source code is available here github.com/rahulpnath/youtube-samples/tree/main/cancellation-token-example
@carlos.maradiaga
@carlos.maradiaga 4 ай бұрын
Thank you so much. @@RahulNath
@informer9261
@informer9261 4 ай бұрын
sir please make an c# full course , 2024
@RahulNath
@RahulNath 4 ай бұрын
Thank you for the suggestion. I'm planning to add more videos around C# fundamentals to this channel.
RECORD TYPES | Exploring C# and DOTNET | Rahul Nath
15:32
Rahul Nath
Рет қаралды 2,9 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 16 МЛН
Викторина от МАМЫ 🆘 | WICSUR #shorts
00:58
Бискас
Рет қаралды 5 МЛН
НРАВИТСЯ ЭТОТ ФОРМАТ??
00:37
МЯТНАЯ ФАНТА
Рет қаралды 8 МЛН
Don't Use Polly in .NET Directly. Use this instead!
14:58
Nick Chapsas
Рет қаралды 55 М.
Concurrent Hosted Service in .NET 8 | .NET Conf 2023
31:12
Forget Controllers and Minimal APIs in .NET!
14:07
Nick Chapsas
Рет қаралды 63 М.
.NET 8 🔥🚀 : Global Error Handling  - Exploring new Features
11:23
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 129 М.
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 52 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 16 МЛН