paint-brush
Why Do You Need a Cancellation Token in C# for Tasks?by@igorlopushko
83,895 reads
83,895 reads

Why Do You Need a Cancellation Token in C# for Tasks?

by Igor Lopushko6mMarch 30th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow
EN

Too Long; Didn't Read

When you run a task in C it may take a while to execute it. In some cases, you would like to cancel such a long operation. A CancellationToken(https://://://.ms.com/en-us/dotnet/api//system.threading.cancellating.tasks?view=net-6.0) enables cooperative cancellation between threads, thread pool work items, or Task(http://www.msn.org/s/windows-windows-tasks) The algorithm follows an algorithm to create an object that signals cancellation to the token. Pass the `CancellatedTokenSource.Token` property as a token object to the task.

Company Mentioned

Mention Thumbnail
featured image - Why Do You Need a Cancellation Token in C# for Tasks?
Igor Lopushko HackerNoon profile picture
Igor Lopushko

Igor Lopushko

@igorlopushko

Programmer, Architect, Teacher

Learn More
LEARN MORE ABOUT @IGORLOPUSHKO'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Igor Lopushko HackerNoon profile picture
Igor Lopushko@igorlopushko
Programmer, Architect, Teacher

TOPICS

Languages

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite