开发者

Passing BeginInvoke as a parameter

开发者 https://www.devze.com 2023-01-28 22:13 出处:网络
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:

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 开发者_StackOverflow社区way to say which version of BeginInvoke I am referring to? (Though I would imagine that would be decided by the parameter type)


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.)

0

精彩评论

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