C# Program to Print the Name of the Current Thread


This is a C# Program to display the name of the current thread.

Problem Description

This C# Program Displays the Name of the Current Thread.

Problem Solution

Here a Thread is the representation of the currently running thread and the name of the current thread is found and displayed.

Program/Source Code

Here is source code of the C# Program to Display the Name of the Current Thread. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

 *  C# Program to Display the Name of the Current Thread
using System;
using System.Threading;
namespace threading
    class Program
        static void Main(string[] args)
            Console.WriteLine("Current information");
            Thread t = Thread.CurrentThread;
            t.Name = "primarythread";
            Console.WriteLine("Thread Name: {0}", t.Name);
            Console.WriteLine("Thread Status: {0}", t.IsAlive);
Program Explanation

In this C# program, using thread constructor create an object variable ‘t’ for the current thread. Name the current thread as primary thread. The IsAlive() function is used to represent the currently running thread. Print the statement as the name of the current thread is found.

Runtime Test Cases
Current information
Thread Name: primarythread
Thread Status: True

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.