Thread class

The simplest and easiest way of creating threads is via the Thread class, which is defined in the System.Threading namespace. This approach has been used since the arrival of .NET version 1.0 and it works with .NET core as well. To create a thread, we need to pass a method that the thread needs to execute. The method can either be parameter-less or parameterized. There are two delegates that are provided by the framework to wrap these functions:

  • System.Threading.ThreadStart
  • System.Threading.ParameterizedThreadStart

We will learn both of these through examples. Before showing you how to create a thread, I will try to explain how a synchronous program works. Later on, we will introduce multithreading so that we understand the ...

Get Hands-On Parallel Programming with C# 8 and .NET Core 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.