将 BeginInvoke 作为参数传递
假设我想要一个传递对象的 BeginInvoke 方法的方法作为参数。我该怎么做呢?该调用如下所示:
MyRandomMethod(SomeControl.BeginInvoke);
MyRandomMethod 的方法定义是什么?
部分问题在于 BeginInvoke 具有重载,因此编译器会混淆我尝试将哪一个作为参数传递。也许我需要找到一种方法来说明我指的是哪个版本的 BeginInvoke? (虽然我想这将由参数类型决定)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MyRandomMethod
必须有一个带有委托的参数,该委托与SomeControl.BeginInvoke
的重载之一匹配。例如:或
(但请不要使用这两个签名重载
MyRandomMethod
本身,否则您只是在自找混乱。)MyRandomMethod
would have to have a parameter with a delegate which matches one of the overloads forSomeControl.BeginInvoke
. For example:or
(But please don't overload
MyRandomMethod
itself with both of these signatures, as otherwise you're just asking for confusion.)