---
title: "Creating, Managing and Destroying Threads in C#"  
description: "In this article I’m explaining about Creating, Managing and destroying threads in c#."  
author: "Anonymous User"  
published: 2014-08-26  
updated: 2019-11-24  
canonical: https://www.mindstick.com/articles/1490/creating-managing-and-destroying-threads-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Creating, Managing and Destroying Threads in C#

In this [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) I’m explaining about Creating, Managing and destroying [threads](https://answers.mindstick.com/qa/106080/how-to-use-twitter-threads-for-comprehensive-storytelling) in

c#.\

if you learn more about Thread [Synchronization](https://www.mindstick.com/articles/11983/synchronization-in-c-sharp) read my [previous](https://yourviews.mindstick.com/view/81421/unlock-2-0-is-just-like-previous-corona-lockdowns) post Thread

Synchronization in c#\

##### Creating Threads:

\

Threads are created by extending the Thread class. The extended Thread class then

calls the Start () method to begin the child thread execution.

```
using System.Threading; namespace ThreadManaging{    class Program    {        public static void ThreadB()        {            Console.WriteLine("Thread B Starts");        }        static void Main(string[] args)        {            ThreadStart thread = new ThreadStart(ThreadB);            Console.WriteLine("In Main Thread: Creating the Thread B");            Thread childThread = new Thread(thread);            childThread.Start();            Console.ReadKey();        }    }}
```

##### Output

\

![Creating, Managing and Destroying Threads in C#](http://www.mindstick.com/MindStickArticle/374cc96c-914a-45fc-976c-03279a0bf9e5/Images/image001.png)

##### Managing Threads:

The Thread class provides various [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) for managing threads. The following

example demonstrates the use of the sleep () method for making a thread pause

for a specific period of time.

```
using System.Threading; namespace ThreadManaging{    class Program    {        public static void ThreadB()        {            Console.WriteLine("Thread B Starts");            int sleep = 10000;            Console.WriteLine("Thread B Paused for {0} Seconds",sleep/1000);            Thread.Sleep(sleep);            Console.WriteLine("Thread B Resumes");        }        static void Main(string[] args)        {            ThreadStart thread = new ThreadStart(ThreadB);            Console.WriteLine("In Main Thread: Creating the Thread B");            Thread childThread = new Thread(thread);            childThread.Start();            Console.ReadKey();        }    }}
```

##### Output

![Creating, Managing and Destroying Threads in C#](http://www.mindstick.com/MindStickArticle/374cc96c-914a-45fc-976c-03279a0bf9e5/Images/image002.png)

##### Destroying Threads:

\

The Abort () method is used for destroying threads. The [runtime](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) aborts the thread

\

by throwing a ThreadAbortException. This [exception](https://www.mindstick.com/articles/61/exception-handling-in-c-sharp) cannot be caught, the [control](https://yourviews.mindstick.com/view/83439/bipartisan-gun-control-bill-passed-in-us-after-decades)

\

is sent to the finally block, if any.

```
using System.Threading; namespace ThreadManaging{    class Program    {        public static void ThreadB()        {            try            {                Console.WriteLine("Thread B Starts");                for (int i = 0; i <= 10; i++)                {                    Thread.Sleep(500);                    Console.WriteLine(i);                }                Console.WriteLine("Thread B Completed");            }            catch (ThreadAbortException e)            {                Console.WriteLine("Thread Abort Exception" + e.Message);            }            finally            {                Console.WriteLine("Could not catch the Thread Exception");            }         }         static void Main(string[] args)        {            ThreadStart threadstart = new ThreadStart(ThreadB);            Console.WriteLine("In Main Thread: Creating the Thread B");            Thread thread = new Thread(threadstart);            thread.Start();            Thread.Sleep(2000);            Console.WriteLine("In Main Thread: Aborting the  Thread B");            thread.Abort();            Console.ReadKey();        }    }}
```

##### \
Output

\

![Creating, Managing and Destroying Threads in C#](http://www.mindstick.com/MindStickArticle/374cc96c-914a-45fc-976c-03279a0bf9e5/Images/image003.png)

in my next post, i'll [explain](https://www.mindstick.com/forum/159699/what-is-a-compilation-error-in-dot-net-core-explain-with-an-example) about Hashtable and [Dictionary](https://www.mindstick.com/articles/1500/hashtable-and-dictionary-in-c-sharp) in c#

---

Original Source: https://www.mindstick.com/articles/1490/creating-managing-and-destroying-threads-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
