Multithreading with C# Cookbook

Over 70 recipes to get you writing powerful and efficient multithreaded, asynchronous, and parallel programs in C# 6.0

Posted by Box XV on April 28, 2020. 6 min read.

Multithreading with C# Cookbook

✅ Publisher: Packt Publishing

✅ Year: April 21, 2016

✅ Authors: Eugene Agafonov

✅ Language: English

✅ Pages: 264

✅ Size: 30.38 MB

✅ Download source code: 9781785881251_Code.zip


Learn

  • Use C# 6.0 asynchronous language features
  • Work with raw threads, synchronize threads, and coordinate their work
  • Develop your own asynchronous API with Task Parallel Library
  • Work effectively with a thread pool
  • Scale up your server application with I/O threads
  • Parallelize your LINQ queries with PLINQ
  • Use common concurrent collections
  • Apply different parallel programming patterns
  • Use Reactive Extensions to run asynchronous operations and manage their options

About

Multi-core processors are synonymous with computing speed and power in today’s world, which is why multithreading has become a key concern for C# developers. Multithreaded code helps you create effective, scalable, and responsive applications.

This is an easy-to-follow guide that will show you difficult programming problems in context. You will learn how to solve them with practical, hands-on, recipes. With these recipes, you’ll be able to start creating your own scalable and reliable multithreaded applications. Starting from learning what a thread is, we guide you through the basics and then move on to more advanced concepts such as task parallel libraries, C# asynchronous functions, and much more.

Rewritten to the latest C# specification, C# 6, and updated with new and modern recipes to help you make the most of the hardware you have available, this book will help you push the boundaries of what you thought possible in C#.

Features

  • Rewritten and updated to take advantage of the latest C# 6 features
  • Learn about multithreaded, asynchronous, and parallel programming through hands-on, code-first examples
  • Use these recipes to build fast, scalable, and reliable applications in C#

Table of contents

  • Multithreading with C# Cookbook Second Edition
  • Credits
  • About the Author
  • About the Reviewers
  • www.PacktPub.com
    • eBooks, discount offers, and more
    • Why Subscribe?

Preface

  • What this book covers
  • What you need for this book
  • Who this book is for
  • Conventions
  • Reader feedback
  • Customer support
    • Downloading the example code
    • Errata
    • Piracy
    • Questions

Chapter 1: Threading Basics

1.1 Introduction

  • Getting ready, How to do it…, How it works…

1.2 Creating a thread in C#

  • Getting ready, How to do it…, How it works…

1.3 Pausing a thread

  • Getting ready, How to do it…, How it works…

1.4 Making a thread wait

  • Getting ready, How to do it…, How it works…

1.5 Aborting a thread

  • Getting ready, How to do it…, How it works…

1.6 Determining a thread state

  • Getting ready, How to do it…, How it works…

1.7 Thread priority

  • Getting ready, How to do it…, How it works…

1.8 Foreground and background threads

  • Getting ready, How to do it…, How it works…

1.9 Passing parameters to a thread

  • Getting ready, How to do it…, How it works…

1.10 Locking with a C# lock keyword

  • Getting ready, How to do it…, How it works…

1.11 Locking with a Monitor construct

  • Getting ready, How to do it…, How it works…

1.12 Handling exceptions

  • Getting ready, How to do it…, How it works…

Chapter 2: Thread Synchronization

2.1 Introduction

  • Getting ready, How to do it…, How it works…

2.2 Performing basic atomic operations

  • Getting ready, How to do it…, How it works…

2.3 Using the Mutex construct

  • Getting ready, How to do it…, How it works…

2.4 Using the SemaphoreSlim construct

  • Getting ready, How to do it…, How it works…

2.5 Using the AutoResetEvent construct

  • Getting ready, How to do it…, How it works…

2.6 Using the ManualResetEventSlim construct

  • Getting ready, How to do it…, How it works…

2.7 Using the CountDownEvent construct

  • Getting ready, How to do it…, How it works…

2.8 Using the Barrier construct

  • Getting ready, How to do it…, How it works…

2.9 Using the ReaderWriterLockSlim construct

  • Getting ready, How to do it…, How it works…

2.10 Using the SpinWait construct

  • Getting ready, How to do it…, How it works…

Chapter 3: Using a Thread Pool

3.1 Introduction

  • Getting ready, How to do it…, How it works…

3.2 Invoking a delegate on a thread pool

  • Getting ready, How to do it…, How it works…

3.3 Posting an asynchronous operation on a thread pool

  • Getting ready, How to do it…, How it works…

3.4 A thread pool and the degree of parallelism

  • Getting ready, How to do it…, How it works…

3.5 Implementing a cancellation option

  • Getting ready, How to do it…, How it works…

3.5 Using a wait handle and timeout with a thread pool

  • Getting ready, How to do it…, How it works…

3.5 Using a timer

  • Getting ready, How to do it…, How it works…

3.5 Using the BackgroundWorker component

  • Getting ready, How to do it…, How it works…

Chapter 4: Using Task Parallel Library

4.1 Introduction

4.2 Creating a task

  • Getting ready, How to do it…, How it works…

4.3 Performing basic operations with a task

  • Getting ready, How to do it…, How it works…

4.4 Combining tasks

  • Getting ready, How to do it…, How it works…

4.5 Converting the APM pattern to tasks

  • Getting ready, How to do it…, How it works…

4.6 Converting the EAP pattern to tasks

  • Getting ready, How to do it…, How it works…

4.7 Implementing a cancelation option

  • Getting ready, How to do it…, How it works…

4.8 Handling exceptions in tasks

  • Getting ready, How to do it…, How it works…

4.9 Running tasks in parallel

  • Getting ready, How to do it…, How it works…

4.10 Tweaking the execution of tasks with TaskScheduler

  • Getting ready, How to do it…, How it works…

Chapter 5: Using C# 6.0

5.1 Introduction

5.2 Using the await operator to get asynchronous task results

  • Getting ready, How to do it…, How it works…

5.3 Using the await operator in a lambda expression

  • Getting ready, How to do it…, How it works…

5.4 Using the await operator with consequent asynchronous tasks

  • Getting ready, How to do it…, How it works…

5.5 Using the await operator for the execution of parallel asynchronous tasks

  • Getting ready, How to do it…, How it works…

5.6 Handling exceptions in asynchronous operations

  • Getting ready, How to do it…, How it works…

5.7 Avoiding the use of the captured synchronization context

  • Getting ready, How to do it…, How it works…

5.8 Working around the async void method

  • Getting ready, How to do it…, How it works…

5.9 Designing a custom awaitable type

  • Getting ready, How to do it…, How it works…

5.10 Using the dynamic type with await

  • Getting ready, How to do it…, How it works…

Chapter 6: Using Concurrent Collections

6.1 Introduction

6.2 Using ConcurrentDictionary

  • Getting ready, How to do it…, How it works…

6.3 Implementing asynchronous processing using ConcurrentQueue

  • Getting ready, How to do it…, How it works…

6.4 Changing asynchronous processing order with ConcurrentStack

  • Getting ready, How to do it…, How it works…

6.5 Creating a scalable crawler with ConcurrentBag

  • Getting ready, How to do it…, How it works…

6.6 Generalizing asynchronous processing with BlockingCollection

  • Getting ready, How to do it…, How it works…

Chapter 7: Using PLINQ

7.1 Introduction

7.2 Using the Parallel class

  • Getting ready, How to do it…, How it works…

7.3 Parallelizing a LINQ query

  • Getting ready, How to do it…, How it works…

7.4 Tweaking the parameters of a PLINQ query

  • Getting ready, How to do it…, How it works…

7.5 Handling exceptions in a PLINQ query

  • Getting ready, How to do it…, How it works…

7.6 Managing data partitioning in a PLINQ query

  • Getting ready, How to do it…, How it works…

7.7 Creating a custom aggregator for a PLINQ query

  • Getting ready, How to do it…, How it works…

Chapter 8: Reactive Extensions

8.1 Introduction

8.2 Converting a collection to an asynchronous Observable

  • Getting ready, How to do it…, How it works…

8.3 Writing custom Observable

  • Getting ready, How to do it…, How it works…

8.4 Using the Subject type family

  • Getting ready, How to do it…, How it works…

8.5 Creating an Observable object

  • Getting ready, How to do it…, How it works…

8.6 Using LINQ queries against an observable collection

  • Getting ready, How to do it…, How it works…

8.7 Creating asynchronous operations with Rx

  • Getting ready, How to do it…, How it works…

Chapter 9: Using Asynchronous I/O

9.1 Introduction

9.2 Working with files asynchronously

  • Getting ready, How to do it…, How it works…

9.3 Writing an asynchronous HTTP server and client

  • Getting ready, How to do it…, How it works…

9.4 Working with a database asynchronously

  • Getting ready, How to do it…, How it works…

9.5 Calling a WCF service asynchronously

  • Getting ready, How to do it…, How it works…

Chapter 10: Parallel Programming Patterns

10.1 Introduction

10.2 Implementing Lazy-evaluated shared states

  • Getting ready, How to do it…, How it works…

10.3 Implementing Parallel Pipeline with BlockingCollection

  • Getting ready, How to do it…, How it works…

10.4 Implementing Parallel Pipeline with TPL DataFlow

  • Getting ready, How to do it…, How it works…

10.5 Implementing Map/Reduce with PLINQ

  • Getting ready, How to do it…, How it works…

Chapter 11: There’s More

11.1 Introduction

11.2 Using a timer in a Universal Windows Platform application

  • Getting ready, How to do it…, How it works…

11.3 Using WinRT from usual applications

  • Getting ready, How to do it…, How it works…

11.4 Using BackgroundTask in Universal Windows Platform applications

  • Getting ready, How to do it…, How it works…

11.5 Running a .NET Core application on OS X

  • Getting ready, How to do it…, How it works…

11.6 Running a .NET Core application on Ubuntu Linux

  • Getting ready, How to do it…, How it works…

https://www.oreilly.com/library/view/multithreading-with-c/9781785881251/
https://www.packtpub.com/application-development/multithreading-c-cookbook-second-edition
https://www.amazon.com/Multithreading-Cookbook-Second-Eugene-Agafonov-ebook/dp/B01BDQK5A4