執行緒操作

iamzxf發表於2015-05-15

獲取當前執行的執行緒,獲得當前執行緒的相關資訊,程式碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace threadDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("主執行緒的狀態");
            Thread currentThread = Thread.CurrentThread;

            currentThread.Name = "the current thread";
            Console.WriteLine("當前執行緒的應用域:{0},ID:{1}",Thread.GetDomain().FriendlyName, Thread.GetDomainID());
            Console.WriteLine("上下文:"+Thread.CurrentContext);
            Console.WriteLine("名稱" + currentThread.Name);
            Console.WriteLine("是否處於活動狀態:"+currentThread.IsAlive);
            Console.WriteLine("狀態:"+currentThread.ThreadState);
            Console.WriteLine("優先順序:" + currentThread.Priority);
            Console.WriteLine("是否為後臺執行緒:"+currentThread.IsBackground);

            Console.ReadLine();

        }
    }
}


相關文章