thieumao

Mảng THREAD đơn giản

Sep 2nd, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7. namespace TestDaLuong
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Thread[] arrTh = new Thread[3];
  14.             arrTh[0] = new Thread(new ThreadStart(a));
  15.             arrTh[1] = new Thread(new ThreadStart(b));
  16.             arrTh[2] = new Thread(new ThreadStart(c));
  17.             for (int i = 0; i < arrTh.Length; i++)
  18.             {
  19.                 arrTh[i].Start();
  20.             }
  21.                 //Thread t1 = new Thread(new ThreadStart(a));
  22.                 //Thread t2 = new Thread(new ThreadStart(b));
  23.                 //Thread t3 = new Thread(new ThreadStart(c));
  24.                 //t1.Start();
  25.                 //t2.Start();
  26.                 //t1.Join();
  27.                 //t2.Join();
  28.                 //t3.Start();
  29.                 Console.ReadLine();
  30.         }
  31.         static void a()
  32.         {
  33.             for (int i = 0; i < 100; i++)
  34.             {
  35.                 Console.Write("1 ");
  36.             }
  37.         }
  38.         static void b()
  39.         {
  40.             for (int i = 0; i < 100; i++)
  41.             {
  42.                 Console.Write("2 ");
  43.             }
  44.         }
  45.         static void c()
  46.         {
  47.             for (int i = 0; i < 100; i++)
  48.             {
  49.                 Console.Write("3 ");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment