开发者

A problem with Invoke(Delegate method, Object[] args) parameter count

开发者 https://www.devze.com 2023-02-11 09:23 出处:网络
I got an exeption like System.Reflection.TargetParameterCountException: Parameter count mismatch. at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boo

I got an exeption like

System.Reflection.TargetParameterCountException: Parameter count mismatch. at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)

But System.Windows.Forms.Control contains only Invoke(Delegate method, params Object[] args) method but not Invoke(Delegate method, Object[] args). And I use it like

Invoke(new SetXDelegate(SetX), value1, value2)

Is it the reason of my problem and I mus开发者_StackOverflow社区t use

Invoke(new SetXDelegate(SetX), new object[] {value1, value2})?

UPDATE

Please recommend if it better to use something like

Invoke((MethodInvoker)delegate { SetX(value1, value2); })

to avoid this kind of problems.

Thanks.


Yes you should. It takes an array of objects

Edit

The problem could be that SetXDelegate doesn't take two parameters.


Actually I think it's complaining that you're passing the wrong number of parameters for SetX to use. What parameters does SetX take?

0

精彩评论

暂无评论...
验证码 换一张
取 消