Csharp/CSharp Tutorial/Thread/Main Thread — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:20, 26 мая 2010

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