EndInvoke() 是可选的,是可选的,还是绝对不是可选的? [英] Is EndInvoke() optional, sort-of optional, or definitely not optional?

查看:16
本文介绍了EndInvoke() 是可选的,是可选的,还是绝对不是可选的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过关于是否每个 BeginInvoke() 都必须与 EndInvoke() 匹配的相互矛盾的意见.是否存在与不调用 EndInvoke() 相关的任何泄漏或其他问题?

I've read conflicting opinions as to whether every BeginInvoke() has to be matched by an EndInvoke(). Are there any leaks or other problems associated with NOT calling EndInvoke()?

推荐答案

Delegate.EndInvoke 被记录为 你应该调用它(即必要 - 否则会发生泄漏) - 来自 msdn:

Delegate.EndInvoke is documented as a thou shalt call this (i.e. necessary - else leaks happen) - from msdn:

重要提示

无论您使用哪种技术,总是调用 EndInvoke 来完成你的异步调用.

No matter which technique you use, always call EndInvoke to complete your asynchronous call.

Control.EndInvoke 可以忽略即发即弃方法 - 来自 msdn:

Control.EndInvoke is OK to ignore for fire-and-forget methods - from msdn:

您可以调用 EndInvoke 来检索从委托返回值,如果必要,但这不是必需的.

You can call EndInvoke to retrieve the return value from the delegate, if neccesary, but this is not required.

但是 - 如果您正在使用 Delegate.BeginInvoke 并且不想要结果,请考虑改用 ThreadPool.QueueUserWorkItem - 它会让生活变得更轻松,并避免 IAsyncResult 等的痛苦.

However - if you are using Delegate.BeginInvoke and don't want the result, consider using ThreadPool.QueueUserWorkItem instead - it'll make life a lot easier, and avoid the pain of IAsyncResult etc.

这篇关于EndInvoke() 是可选的,是可选的,还是绝对不是可选的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆