Csharp/C Sharp/Thread/WaitCallback
Версия от 15:31, 26 мая 2010; (обсуждение)
new WaitCallback
using System;
using System.Threading;
class ThreadPoolDemo {
public void LongTask1(object obj) {
for (int i = 0; i <= 999; i++) {
Console.WriteLine("Long Task 1 is being executed");
}
}
public void LongTask2(object obj) {
for (int i = 0; i <= 999; i++) {
Console.WriteLine("Long Task 2 is being executed");
}
}
static void Main() {
ThreadPoolDemo tpd = new ThreadPoolDemo();
for (int i = 0; i < 50; i++) {
ThreadPool.QueueUserWorkItem(new WaitCallback(tpd.LongTask1));
ThreadPool.QueueUserWorkItem(new WaitCallback(tpd.LongTask2));
}
Console.Read();
}
}