System.Reflection.MethodInfo.Invoke 和多线程(带返回类型)
我一直在浏览网站上的其他问题并找到了这篇文章。
Ben Voigts 的回答非常有用,我相信我让它在我的系统中工作。
我遇到的问题是,在某些情况下,我需要从方法调用返回一个值。
我本来打算对该帖子发表评论,但我的代表不够高,无法发表评论。
希望 Ben 能看到这篇文章,或者其他人能够扩展他的答案,包括如何返回一个值。
如果您需要任何其他信息,请告诉我。
亲切的问候
阿什
I have been looking through the other questions on the site and have found this post.
Ben Voigts answer is very useful and I believe I have it working in my system.
The issue I have is that in some cases I will need a value to be returned from the method invocation.
I was going to just leave a comment on that post but my rep isnt high enough to leave comments.
Hopefully either Ben will see this post or someone else will be able to extend his answer to include how to return a value.
Please let me know if there is any other information you require.
Kind Regards
Ash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你基本上有两个选择。要么同步调用 MethodInfo.Invoke 并等待结果。或者您设置一个回调方法,以便在调用完成后调用。从您链接到的示例扩展:
我添加了一个额外的参数,该参数采用一个委托,该委托将在调用完成时被调用。
然后你可以这样使用它:
You basically have two options. Either you call the MethodInfo.Invoke synchronously and wait for the result. Or you set up a callback method to get called once the invocation is complete. Extending from the example you linked to:
I added an extra parameter which takes a delegate that will get called when the invocation is done.
Then you can use it this way: