Display main thread"s name
using System;
using System.Threading;
class MainClass {
public static void Main() {
Thread thrd = Thread.CurrentThread;
if(thrd.Name == null)
Console.WriteLine("Main thread has no name.");
else
Console.WriteLine("Main thread is called: " + thrd.Name);
}
}
Main thread has no name.
Display main thread"s priority
using System;
using System.Threading;
class MainClass {
public static void Main() {
Thread thrd = Thread.CurrentThread;
Console.WriteLine("Priority: " + thrd.Priority);
}
}
Priority: Normal
Get the main thread
using System;
using System.Threading;
class MainClass {
public static void Main() {
Thread thrd;
// Get the main thread.
thrd = Thread.CurrentThread;
}
}
Set main thread"s name
using System;
using System.Threading;
class MainClass {
public static void Main() {
Thread thrd = Thread.CurrentThread;
thrd.Name = "Main Thread";
Console.WriteLine("Main thread is now called: " + thrd.Name);
}
}
Main thread is now called: Main Thread
Set the main thread"s priority
using System;
using System.Threading;
class MainClass {
public static void Main() {
Thread thrd = Thread.CurrentThread;
thrd.Priority = ThreadPriority.AboveNormal;
Console.WriteLine("Priority is now: " + thrd.Priority);
}
}
Priority is now: AboveNormal