Okay... with a fuller example, it's reasonably easy to see what's going on.
The problem is that the delegate expects a single parameter which must be an object array.
Now look at how you're invoking it:
private void ChangeDay(Delegate del, params object[] args)
{
if (this.InvokeRequired)
{
methodDelegate = del;
this.BeginInvoke(new VoidDelegate(RouterDelegate), args);
}
}
The args
here is expected to be an array of arguments... multiple of them. So if your delegate took two string parameters, you'd have an object[]
with a length of two, each of element of which would be a string reference.
So what you want is an object[]
with length 1, whose sole element is a reference to another object[]
. You can do that easily:
this.BeginInvoke(new VoidDelegate(RouterDelegate), new object[] { args });
and the same thing in RouterDelegate
:
methodDelegate.DynamicInvoke(new object[] { args });
At that point, I believe everything will work fine (in terms of delegate invocation - you should not be sleeping in the UI thread, but that's a different matter).