Cancellation Token in .NET | Exploring C# and DOTNET

Rahul Nath
Rahul Nath
4.2 هزار بار بازدید - 4 ماه پیش - Hey 👋 Imagine having a
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 - https://www.rahulpnath.com/blog/cance...
🔗 Code - https://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 - https://bit.ly/mycsharp
📹 ASP Series - https://bit.ly/asp-net-core-series
📹Azure Series - https://bit.ly/azure-series
📹AWS Series - https://bit.ly/aws-net-series
📹RabbitMQ Series - https://bit.ly/rabbitmq-net-series

Come say hi! ✋
🎙️Uses - https://www.rahulpnath.com/uses
🌍Blog - https://www.rahulpnath.com/
✉ Subscribe to my Newsletter - https://www.rahulpnath.com/subscribe
🐦Twitter - Twitter: rahulpnath
📸Instagram - Instagram: rahulpnath

#dotnet #csharp
4 ماه پیش در تاریخ 1402/12/24 منتشر شده است.
4,277 بـار بازدید شده
... بیشتر