---
title: "Foreground and Background thread in C# Threading"  
description: "By default, When we create thread is implicitly foreground thread, foreground thread keeps application is alive as long as any one of foreground threa"  
author: "Anonymous User"  
published: 2011-08-26  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/620/foreground-and-background-thread-in-c-sharp-threading  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Foreground and Background thread in C# Threading

By default, When we create thread is implicitly foreground thread, foreground thread keeps application is alive as long as any one of foreground thread is active where as background thread do not. When all foreground thread is terminated then background thread implicitly terminated.\

Foreground and background does not affect to each other.

##### Example:

To creating Foreground and Background thread writes the following code.

```
using System.Threading;  namespace ForegroundThread{     class Program    {         static voidMain(string[] args)         {             // Create ThreadA object             Thread back= newThread(newThreadStart(ChildThreadA));             // Create ThreadB object             Thread fore= newThread(newThreadStart(ChildThreadB));             // Set ThreadB as background thread            back.IsBackground= true;            back.Start();            fore.Start();                          Thread.CurrentThread.Name= "Main";            for (inti=0; i<20; i++)            {                 if (i==5)                     fore.Abort();  //Abort Foreground thread                Console.WriteLine(Thread.CurrentThread.Name);            }         }         public staticvoidChildThreadA()         {             for (inti=0; i<10; i++)            {                 Console.WriteLine("Child thread A:");            }         }         public staticvoidChildThreadB()         {             for (inti=0; i<10; i++)            {                 Console.WriteLine("Child thread B:");            }         }    }}
```

In above program after terminating of foreground thread the application will run until main thread is not terminated after terminating main thread application will be terminate.

##### Output:

![Foreground and Background thread in C# Threading](https://www.mindstick.com/mindstickarticle/0f13e370-df87-4eb3-9e44-e169e361b7a0/images/2c4e8ca3-96a2-4e2c-8544-c04b11dd708a.png)

---

Original Source: https://www.mindstick.com/articles/620/foreground-and-background-thread-in-c-sharp-threading

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
