using System;
using System.Threading;
public class MyValue {
public string MyString;
public int Value;
public MyValue(string text, int number) {
MyString = text;
Value = number;
}
}
public class Example {
public static void Main() {
MyValue ti = new MyValue("{0}", 42);
if (ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti)) {
Thread.Sleep(1000);
Console.WriteLine("Main thread exits.");
}
else {
Console.WriteLine("Unable to queue ThreadPool request.");
}
}
static void ThreadProc(Object stateInfo) {
MyValue ti = (MyValue) stateInfo;
Console.WriteLine(ti.MyString, ti.Value);
}
}
|