这段代码:
var returnType = GetDelegateReturnType(typeof(TimerCallback)); var methodParameters = typeof(TimerCallback).GetMethod("Invoke").GetParameters().Select(x => x.ParameterType).ToArray(); var handler = new System.Reflection.Emit.DynamicMethod("", returnType, methodParameters, typeof(ArgumentNullTest)); var generator = handler.GetILGenerator(); generator.Emit(System.Reflection.Emit.OpCodes.Ldloc, 1); 生成器.Emit(System.Reflection.Emit.OpCodes.Ret); var timerCallback = (TimerCallback)handler.CreateDelegate(typeof(TimerCallback)); var timer = new Timer(timerCallback, null, 0, 0); var timer2 = new Timer(o => { }, null, 0, 0);
InvalidProgramException
创建第二个计时器时抛出一个。TimerCallback
创建每个反射时我做错了什么?