问题描述
我读过关于是否每个 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() 是可选的,是可选的,还是绝对不是可选的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)