How do I implement multithreading in C#

Multithreading in C# allows you to run multiple threads concurrently, enabling you to make better use of system resources and improve the performance of your applications. Here’s a simple example of how to implement multithreading in C#:

using System; using System.Threading; class Program { static void Main() { Thread thread1 = new Thread(PrintNumbers); Thread thread2 = new Thread(PrintLetters); thread1.Start(); thread2.Start(); thread1.Join(); thread2.Join(); Console.WriteLine("Both threads have completed."); } static void PrintNumbers() { for (int i = 1; i <= 5; i++) { Console.WriteLine(i); Thread.Sleep(1000); // Simulate work } } static void PrintLetters() { for (char c = 'A'; c <= 'E'; c++) { Console.WriteLine(c); Thread.Sleep(1000); // Simulate work } } }

multithreading C# threads concurrency .NET