Q:

C# program to print the name of the current thread

0

C# program to print the name of the current thread

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

/*
 * Program to print the Name of the Current Thread
 */
using System;
using System.Threading;

class MyThreadClass
{
    static void Main(string[] args)
    {
        Thread t = Thread.CurrentThread;
        t.Name = "MyNewThread";

        Console.WriteLine("Thread information:");
        Console.WriteLine("\tName of the thread: "+t.Name);
        Console.WriteLine("\tStatus of thread  : "+(t.IsAlive==true?"Alive":"Not Alive"));
    } 
}

Output:

Thread information:
        Name of the thread: MyNewThread
        Status of thread  : Alive
Press any key to continue . . .

Explanation:

In the above program, we created a class MyThreadClass that contains the Main() method to start the execution of the program. In the Main() method, we created using Thread.CurrentThread property then we assigned thread name and then print thread information.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now