如何放弃 System.DirectoryServices.Protocols 中长时间运行的搜索
我一直在尝试找出如何取消 System.DirectoryServices.Protocols 中长时间运行的 AD 搜索。 有人可以帮忙吗?
我查看了 RootDSE 上的 supportControl/supportedCapability 属性,它们不包含 1.3.6.1.1.8 OID,因此我认为这意味着它不支持此处定义的 LDAP CANCEL 扩展操作: https://www.rfc-editor.org/rfc/rfc3909
这留下了原始的 LDAP ABANDON 命令(请参阅此处查看列表)。 但似乎没有匹配的 DirectoryRequest 类。
有人有主意吗?
I've been trying to work out how to cancel a long-running AD search in System.DirectoryServices.Protocols. Can anyone help?
I've looked at the supportControl/supportedCapabilities attributes on RootDSE and they don't contain the 1.3.6.1.1.8 OID so I think that means it doesn't support the LDAP CANCEL extended operation as defined here: https://www.rfc-editor.org/rfc/rfc3909
That leaves the original LDAP ABANDON command (see here for list). But there doesn't seem to be a matching DirectoryRequest Class.
Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想我已经找到了答案:马丁,当我阅读您的建议时,我遇到了LdapConnection 类上的 Abort 方法。 我没想到会在那里找到它:从 LDAP 文档开始,我本以为它只是另一个 LDAPMessage,但 MS 的人似乎将它视为一种特殊情况。 如果有人熟悉 LDAP 的非 MS 实现并且可以评论 MS 方法是否典型,我将不胜感激,以提高我的理解。
I think I've found my answer: whilst I was reading around your suggestion, Martin, I came across the Abort method on the LdapConnection class. I didn't expect to find it there: starting out from the LDAP documentation I'd expected to find it as just another LDAPMessage but the MS guys seem to have treated it as a special case. If anyone is familiar with a non-MS implementation of LDAP and can comment on whether the MS approach is typical, I'd appreciate it to improve my understanding.
我认为,但我并不肯定,没有取消的异步查询。 它具有异步属性,但它允许填充集合,与取消无关。 我能提供的最好的方法是将您的查询放在后台工作线程中,并放置一个异步回调,该回调将在返回时处理答案。 如果用户决定取消,只需取消后台工作线程即可。 即使在 ldap 服务器完成查询之前您还没有释放它,您也将释放您的应用程序。 您可以在 http://www.c 找到有关后台工作线程的信息-sharpcorner.com/UploadFile/LivMic/BGWorker07032007000515AM/BGWorker.aspx
清理活动目录对象时不要忘记调用 .Dispose() 以防止内存泄漏。
I think, but I'm not positive, there is no asynch query with a cancel. It has an asynch property but it's to allow a collection to be filled, nothing to do with cancelling. The best I can offer is to put your query in a background worker thread and put an asynch callback that will deal with the answer when it comes back. If the user decides to cancel, you can just cancel the background worker thread. You'll free your app up, even if you haven't freed the ldap server up until it finishes it's query. You can find info on background worker threads at http://www.c-sharpcorner.com/UploadFile/LivMic/BGWorker07032007000515AM/BGWorker.aspx
Don't forget to call .Dispose() when cleaning up your active directory objects to prevent memory leaks.
如果查询还会产生很多数据,您可以通过分页放弃它们。 指定 PageResultRequestControl查询中的选项,给出相当小的页面大小(IIUC,1000 是默认页面大小)。 IIUC,每次获得页面时,您都会发送新的请求(将 cookie 从一个响应传递到下一个请求)。 当您选择取消查询时,请发送另一个预期结果为零的请求。
If the query will produce many data also, you can abandon them through paging. Specify a PageResultRequestControl option in the query, giving a fairly low page size (IIUC, 1000 is the default page size). IIUC, you'll send new requests every time you got a page (passing cookies from one response into the next request). When you choose to cancel the query, send another request with zero expected results.