爲了另一個線程更改控制,我需要調用一個委託來改變控制然而,它拋出一個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
調用拋出一個異常?
不知道爲什麼需要'Invoke'考慮到_current線程的'button1_Click'裏面已經是UI thread_ – MickyD