C# Program to Check Status of the Current Thread

This is a C# Program to obtain status of the current thread.

Problem Description

This C# Program Obtains the Status of the Current Thread.

Problem Solution

Here a Thread is the representation of the currently running thread and the true or false is displayed as a result of the status method.

Program/Source Code

Here is source code of the C# Program to Obtain Status 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 Obtain Status 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);
 
            Console.ReadKey();
        }
 
    }
}
Program Explanation

In this C# program, using if else condition statement. Check the CurrentThread() method value is equal to null. If the condition is true, then execute the statement and print the statement as thread has been named. Here a Thread is the representation of the currently running thread and then true or false is displayed as a result of the status method.

advertisement
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.

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification 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
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 20s–40s and exploring new directions in your career, I also offer mentoring. Learn more here.