Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Parallel Programming with C# 8 and .NET Core 3

You're reading from   Hands-On Parallel Programming with C# 8 and .NET Core 3 Build solid enterprise software using task parallelism and multithreading

Arrow left icon
Product type Paperback
Published in Dec 2019
Publisher Packt
ISBN-13 9781789132410
Length 346 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Shakti Tanwar Shakti Tanwar
Author Profile Icon Shakti Tanwar
Shakti Tanwar
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Section 1: Fundamentals of Threading, Multitasking, and Asynchrony FREE CHAPTER
2. Introduction to Parallel Programming 3. Task Parallelism 4. Implementing Data Parallelism 5. Using PLINQ 6. Section 2: Data Structures that Support Parallelism in .NET Core
7. Synchronization Primitives 8. Using Concurrent Collections 9. Improving Performance with Lazy Initialization 10. Section 3: Asynchronous Programming Using C#
11. Introduction to Asynchronous Programming 12. Async, Await, and Task-Based Asynchronous Programming Basics 13. Section 4: Debugging, Diagnostics, and Unit Testing for Async Code
14. Debugging Tasks Using Visual Studio 15. Writing Unit Test Cases for Parallel and Asynchronous Code 16. Section 5: Parallel Programming Feature Additions to .NET Core
17. IIS and Kestrel in ASP.NET Core 18. Patterns in Parallel Programming 19. Distributed Memory Management 20. Assessments 21. Other Books You May Enjoy

How to cancel tasks

Another important function of the TPL is to equip developers with ready-made data structures to cancel running tasks. Those of you that have a classic threading background will be aware of how difficult it used to be to make threads support canceling with all the custom home-grown logic, but this is no longer the case. The .NET Framework provides two classes to support task cancellation:

  • CancellationTokenSource: This class is responsible for creating cancellation tokens and passing the cancellation request to all the tokens that were created via the source
  • CancellationToken: This class is used by listeners to monitor the current state of a request

To create tasks that can be canceled, we need to perform the following steps:

  1. Create an instance of the System.Threading.CancellationTokenSource class, which further provides a System.Threading.CancellationToken...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime