---
title: "Multithreading in C#"  
description: "In this blog, I’m trying to explain the concept of multithreading in c#  Multithreading is the ability of an operating system to concurrently run prog"  
author: "Sumit Kesarwani"  
published: 2013-05-14  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/509/multithreading-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Multithreading in C#

In this blog, I’m trying to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of [multithreading in c#](https://www.mindstick.com/forum/159901/how-can-i-work-with-threads-and-multithreading-in-c-sharp-please-provide-a-sample)\

Multithreading is the ability of an [operating system](https://www.mindstick.com/articles/229069/operating-system-development) to concurrently run [programs](https://www.mindstick.com/forum/157528/how-exceptions-can-be-handled-in-sql-server-programs) that have been divided into subcomponents, or threads. Multithreading contains two or more program codes which run concurrently without affecting to each other and each program codes is called thread.

In .NET [framework](https://www.mindstick.com/forum/34615/software-framework-vs-library), System.Threading [namespace](https://www.mindstick.com/articles/12552/namespace) provides classes and [interfaces](https://www.mindstick.com/articles/12100/interfaces-in-java-real-life-example) that enable multi-threaded programming.

There are two types to create thread in C#, first one is through the Thread Class and second one is through the ThreadStart [Delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp).

Example -1

Creating Thread with Thread Class

```
using System;using System.Threading;namespace ThreadConsoleApplication2{    class Program    {        static void Main(string[] args)        {          Thread t = new Thread(y);            t.Start();            for (int i = 0; i < 5; i++)            {                Console.WriteLine("X");            }        }        static void y()        {            for (int i = 0; i < 5; i++)            {                Console.WriteLine("Y");            }        }    }}
```

##### Output

X

X

X

X

X

Y

Y

Y

Y

##### Example-2

Creating Thread with ThreadStart Delegate

```
using System;using System.Threading;namespace ThreadConsoleApplication3{    class Program    {        static void Main(string[] args)        {            Thread t = new Thread(new ThreadStart(display));            t.Start();            for (int i = 0; i < 3; i++)            {                Console.WriteLine("Thread A");            }        }        static void display()        {            for (int i = 0; i < 3; i++)            {                Console.WriteLine("Thread B");            }        }    }}
```

##### Output

Thread A

Thread A

Thread A

Thread B

Thread B

Thread B

---

Original Source: https://www.mindstick.com/blog/509/multithreading-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
