1 class UsingThreadJoin
2 {
3 static void Main(string[] args)
4 {
5 ThreadStart o = new ThreadStart(SimpleWork);
6 Thread[] t = new Thread[5];
7 for (int x = 0; x < 5; ++x)
8 {
9 t[x] = new Thread(o);
10 t[x].Name = "執行緒" + x.ToString();
11 t[x].Priority = ThreadPriority.Normal;
12 t[x].Start();
13 }
14 foreach (Thread temp in t)
15 {
16 temp.Join();
17 }
18 Console.WriteLine("finish");
19 }
20 static void SimpleWork()
21 {
22 Console.WriteLine("Thread: {0} name: {1}",
23 Thread.CurrentThread.ManagedThreadId,
24 Thread.CurrentThread.Name);
25 Thread.Sleep(100);
26 }
27 }
沒有留言:
張貼留言