This page in the MS documentation ,涵盖了 Windows 窗体应用程序中的异步,指出:
You can call EndInvoke to retrieve the return value from the delegate, if neccesary, but this is not required. (emphasis added)
This page covering the general case of asynchronous delegates , 陈述了一些不同的事情:
No matter which technique you use, always call EndInvoke to complete your asynchronous call.
这两者似乎是直接冲突的。
哪个是真的?有人可以解释吗?
另见,a post by Phil Haack .
Related: Is EndInvoke optional, sort-of optional, definitely not optional?
最佳答案
除非接口(interface)的文档明确说明,否则您必须为每个调用 BeginInvoke 的地方调用 EndInvoke。主要原因是 EndInvoke 是所有者可以安全地释放某些可能分配给 BeginInvoke 调用(例如 WaitHandle)的资源的唯一时间。
但这条规则也有异常(exception)。 Control.BeginInvoke 等 API 不需要 EndInvoke,但它在文档中是明确的。
关于.net - 每个 BeginInvoke 之后必须跟一个 EndInvoke 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1274276/