是EndInvoke会()可选的排序可选,或绝对不是可有​​可无的,? [英] Is EndInvoke() optional, sort-of optional, or definitely not optional?

查看:117
本文介绍了是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检索
  从委托的返回值,如果
  neccesary,但是这不是必需的。

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天全站免登陆