Background and foreground thread in C#


A thread is defined as the execution path of a program. Each thread defines a unique flow of control

Background Threads

When the foreground threads will close, the background threads will be terminated.

The property used for background thread is IsBackground that gets or sets a value indicating whether a thread is a background thread. The default value of this property would be false because the default threads created are Foreground Threads.

To create a background thread −

Thread bgThread = new Thread(tStart);
bgThread.IsBackground = true;
bgThread.Start();

Foreground Threads

Foreground threads continue to run until the last foreground thread is terminated.

When all the foreground threads are stopped, the application is closed. The default threads that are created are foreground threads.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

469 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements