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

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

问题描述

对于每个BeginInvoke()是否必须通过EndInvoke()进行匹配,我已经看到了矛盾的观点。有没有与NOT调用EndInvoke()相关联的泄漏或其他问题?

解决方案

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屋!

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