EndInvoke 的参数

发布于 2024-10-02 17:44:04 字数 188 浏览 1 评论 0原文

我有一个委托 foo,我对其调用 BeginInvoke 并将 IAsyncResult 检索到 var bar 中。

然后我调用 EndInvoke(bar) ,一切都很顺利。

为什么我必须通过 bar 来调用?究竟发生了什么需要这样做?我意识到 Endinvoke 是清除可能的资源泄漏所必需的,但这个参数没有意义......

I have a delegate foo, I call BeginInvoke on it and retrieve the IAsyncResult into a var bar.

I then call EndInvoke(bar) and everything is happy.

Why do I have to pass bar to endinvoke? what exactly is going on that demands this? I realize Endinvoke is mandatory to clear possible resource leaks, but this parameter makes no sense...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-10-09 17:44:04

不,这是完全有道理的。您可能多次调用委托 - EndResult 如何知道您正在谈论哪个调用? IAsyncResult 基本上封装了异步任务。

如果您一直在研究任何较新的东西,请将 IAsyncResult 视为有点像 Task 的不透明版本。

No, it makes perfect sense. You could have invoked the delegate multiple times - how is EndResult meant to know which invocation you're talking about? The IAsyncResult is basically encapsulating the asynchronous task.

If you've been looking at any of the newer stuff, think of IAsyncResult as a little bit like an opaque version of Task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文