隔一秒增加一的自增器
/// <summary> /// 测试案例 /// </summary> class Program { static void Main(string[] args) { for (int i = 0; i < 5; i++) { ThreadPool.QueueUserWorkItem(add, 0); for (int j = 0; j < 5; j++) { Thread.Sleep(1000); } } Console.ReadLine(); } /// <summary> /// 隔一秒增加一的自增器 /// </summary> /// <param name="num"></param> private static void add(object state) { int num = (int)state; for (int i = 0; i < 3; i++) { Thread.Sleep(1000); num++; Console.WriteLine(num); } } }