Vaccano
Vaccano

Reputation: 82341

Passing BeginInvoke as a parameter

Suppose I want to have a method that passes the BeginInvoke method of an object as a parameter. How would I do that? The call looks like this:

MyRandomMethod(SomeControl.BeginInvoke);

What would the method definition for MyRandomMethod be?

Part of the problem is that BeginInvoke has overloads, so the compiler gets confused as to which one I am try to pass as a parameter. Maybe I need to find a way to say which version of BeginInvoke I am referring to? (Though I would imagine that would be decided by the parameter type)

Upvotes: 1

Views: 309

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500495

MyRandomMethod would have to have a parameter with a delegate which matches one of the overloads for SomeControl.BeginInvoke. For example:

public void MyRandomMethod(Func<Delegate, IAsyncResult> foo)

or

public void MyRandomMethod(Func<Delegate, object[], IAsyncResult> foo)

(But please don't overload MyRandomMethod itself with both of these signatures, as otherwise you're just asking for confusion.)

Upvotes: 3

Related Questions