- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
How to Cancel Tasks in C# - Using CancellationTokenSource and CancellationToken
In this video, I answer the question "How to Cancel Tasks in C# using the CancellationTokenSource and CancellationToken objects?".
Cancelling a Task in C# is pretty straight foreword. There are actually several ways to cancel a Task in C#. The three most common ways to cancel a task are by polling , by registering a callback, and by using the Wait handle. You can even cancel multiple tokens simultaneously.
In this video, we use the polling approach as that is meant for scenarios in which you have long-running computations that loop or recurse.
The general pattern used to cancel a task is:
- Instantiate a CancellationTokenSource object, which manages and sends cancellation notification to the individual cancellation tokens.
- Pass the token returned by the CancellationTokenSource.Token property to each task or thread that listens for cancellation.
- Provide a mechanism for each task or thread to respond to cancellation.
- Call the CancellationTokenSource.Cancel method to provide notification of cancellation.
It's important to note that you should always call the CancellationTokenSource.Dispose method when you have finished using the cancellation token source to free any unmanaged resources it holds.
Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
https://pluralsight.pxf.io/bE3rB
Sponsor Me:
https://github.com/sponsors/brianlagunas
Follow Me:
Twitter: https://twitter.com/brianlagunas
Twitch: https://www.twitch.tv/brianlagunas
Blog: http://brianlagunas.com
GitHub: https://github.com/brianlagunas
Видео How to Cancel Tasks in C# - Using CancellationTokenSource and CancellationToken канала Brian Lagunas
Cancelling a Task in C# is pretty straight foreword. There are actually several ways to cancel a Task in C#. The three most common ways to cancel a task are by polling , by registering a callback, and by using the Wait handle. You can even cancel multiple tokens simultaneously.
In this video, we use the polling approach as that is meant for scenarios in which you have long-running computations that loop or recurse.
The general pattern used to cancel a task is:
- Instantiate a CancellationTokenSource object, which manages and sends cancellation notification to the individual cancellation tokens.
- Pass the token returned by the CancellationTokenSource.Token property to each task or thread that listens for cancellation.
- Provide a mechanism for each task or thread to respond to cancellation.
- Call the CancellationTokenSource.Cancel method to provide notification of cancellation.
It's important to note that you should always call the CancellationTokenSource.Dispose method when you have finished using the cancellation token source to free any unmanaged resources it holds.
Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
https://pluralsight.pxf.io/bE3rB
Sponsor Me:
https://github.com/sponsors/brianlagunas
Follow Me:
Twitter: https://twitter.com/brianlagunas
Twitch: https://www.twitch.tv/brianlagunas
Blog: http://brianlagunas.com
GitHub: https://github.com/brianlagunas
Видео How to Cancel Tasks in C# - Using CancellationTokenSource and CancellationToken канала Brian Lagunas
how to cancel tasks in c# cancel task with cancellationtoken cancellationtoken c# cancellationtokensource c# cancellationtoken c# task cancellationtoken example c# cancellationtokensource example cancellationtokensource tutorial cancellationtokensource async await cancellationtoken cancel task c# cancellationtoken example cancellationtokensource cancel cancellationtokensource cancellationtokensource example c# cancellationtoken .net core cancel task C#
Комментарии отсутствуют
Информация о видео
6 августа 2020 г. 19:00:08
00:06:23
Другие видео канала





















