EndInvoke()是可选的,可选的,绝对不是可选的? [英] Is EndInvoke() optional, sort-of optional, or definitely not optional?
问题描述
Delegate.EndInvoke被记录为您应该 msdn将此(即必要 - 否则发生泄漏) :
重要提示
无论使用哪种技术,
总是调用EndInvoke来完成
异步调用。
控件。 EndInvoke是可以忽略的一个不要忘记的方法 - 从 msdn :
您可以调用EndInvoke从委托中获取
返回值,如果
必需,但这是不需要。
但是 - 如果您使用 Delegate.BeginInvoke
不想要结果,考虑使用 ThreadPool.QueueUserWorkItem
而不是让生活更容易,并避免 IAsyncResult
等。
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 is documented as a thou shalt call this (i.e. necessary - else leaks happen) - from msdn:
Important Note
No matter which technique you use, always call EndInvoke to complete your asynchronous call.
Control.EndInvoke is OK to ignore for fire-and-forget methods - from msdn:
You can call EndInvoke to retrieve the return value from the delegate, if neccesary, but this is not required.
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屋!