【发布时间】:2017-06-17 12:49:22
【问题描述】:
为了通过另一个线程更改控件,我需要调用委托来更改控件但是,它正在抛出TargetParameterCountException:
private void MethodParamIsObjectArray(object[] o) {}
private void MethodParamIsIntArray(int[] o) {}
private void button1_Click(object sender, EventArgs e)
{
// This will throw a System.Reflection.TargetParameterCountException exception
Invoke(new Action<object[]>(MethodParamIsObjectArray), new object[] { });
// It works
Invoke(new Action<int[]>(MethodParamIsIntArray), new int[] { });
}
为什么用MethodParamIsObjectArray 调用会抛出异常?
【问题讨论】:
-
不知道为什么在
button1_Click中需要Invoke考虑到当前线程已经是UI 线程