Is EndInvoke() optional, sort-of optional, or definitely not optional?(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 来检索从委托返回值,如果必要,但这不是必需的.
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() 是可选的,是可选的,还是绝对不是可选的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EndInvoke() 是可选的,是可选的,还是绝对不是可选的?
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
