Csharp/CSharp Tutorial/Thread/Main Thread
Содержание
Display main thread"s name
<source lang="csharp">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); }
}</source>
Main thread has no name.
Display main thread"s priority
<source lang="csharp">using System; using System.Threading;
class MainClass {
public static void Main() { Thread thrd = Thread.CurrentThread; Console.WriteLine("Priority: " + thrd.Priority); }
}</source>
Priority: Normal
Get the main thread
<source lang="csharp">using System; using System.Threading;
class MainClass {
public static void Main() { Thread thrd; // Get the main thread. thrd = Thread.CurrentThread; }
}</source>
Set main thread"s name
<source lang="csharp">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); }
}</source>
Main thread is now called: Main Thread
Set the main thread"s priority
<source lang="csharp">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); }
}</source>
Priority is now: AboveNormal