数据槽对每个线程来说是唯一的,,其它任线程(即使是子线程)都 无法获取这些数据 例子如下 using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ConsoleApplication1 { class Program { private static Random rnd; private static LocalDataStoreSlot objSlot; static void Main(string[] args) { rnd = new Random(); objSlot = Thread.AllocateDataSlot(); Thread[] newThreads = new Thread[4]; for (int i = 0; i < newThreads.Length; i++) { newThreads[i] = new Thread(new ThreadStart(fnTest)); newThreads[i].Start(); } Console.Read(); } private static void fnTest() { Thread.SetData(objSlot ,rnd.Next (1,200)); Console.WriteLine ("线程 ID: {0},数据{1}",AppDomain.GetCurrentThreadId().ToString(),Thread.GetData(objSlot ).ToString () ); Thread.Sleep(1000); Console.WriteLine("线程 ID: {0} 数据:{1}",AppDomain.GetCurrentThreadId().ToString (),Thread.GetData(objSlot).ToString () ); Console.WriteLine(""); } } }