thieumao

Test đa luồng

Sep 2nd, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 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.             // Tạo mảng 10 thread
  14.             Thread[] arrTh = new Thread[10];
  15.             for (int i = 0; i < arrTh.Length; i++)
  16.             {
  17.                 // Bắt đầu các thread với việc gán tham số
  18.                 ParameterizedThreadStart st = new ParameterizedThreadStart(Batdau);
  19.                 arrTh[i] = new Thread(st);
  20.                 arrTh[i].Start(i);
  21.             }
  22.             Console.ReadLine();
  23.         }
  24.         static void Batdau(object info)
  25.         {
  26.             // Lấy giá trị từ tham số sau đó convert sang int
  27.             int value = (int)info + 10;
  28.             Console.WriteLine(value);
  29.         }
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment