using System.Reflection.Emit;
static void Main(string[] args)
DynamicMethod threadMethod = new DynamicMethod("MyThreadMethod", typeof(void), new Type[] { typeof(int) });
ILGenerator threadILGenerator = threadMethod.GetILGenerator();
threadILGenerator.Emit(OpCodes.Ldarg_0);
threadILGenerator.Emit(OpCodes.Ldftn, typeof(Program).GetMethod("WaitCallback", BindingFlags.NonPublic | BindingFlags.Static));
threadILGenerator.Emit(OpCodes.Newobj, typeof(WaitCallback).GetConstructor(new Type[] { typeof(object), typeof(IntPtr) }));
threadILGenerator.Emit(OpCodes.Call, typeof(ThreadPool).GetMethod("QueueUserWorkItem", new Type[] { typeof(WaitCallback) }));
threadILGenerator.Emit(OpCodes.Ret);
threadMethod.Invoke(null, new object[] { 5 });
private static void WaitCallback(object state)
Console.WriteLine("Hello from the thread pool! State = {0}", state);