c# – 如何在使用DirectorySearcher时确定ClientTimeout
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如何在使用DirectorySearcher时确定ClientTimeout,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1419字,纯文字阅读大概需要3分钟。
内容图文
![c# – 如何在使用DirectorySearcher时确定ClientTimeout](/upload/InfoBanner/zyjiaocheng/827/3cc774178aef4d2b9e416f86b824be55.jpg)
使用System.DirecoryServices.DirectorySearcher时,如何确定ClientTimeOut是否已发生或搜索是否自然返回空的SearchResultCollection?
给出以下片段
using (var searcher = new DirectorySearcher(adRoot))
{
searcher.Filter = "SomeFilter";
searcher.PropertiesToLoad.Add("givenname");
searcher.PropertiesToLoad.Add("sn");
searcher.PropertiesToLoad.Add("department");
searcher.PropertiesToLoad.Add("samaccountname");
searcher.ClientTimeout = TimeSpan.FromSeconds(10);
using (var results = searcher.FindAll())
{
//haldle results
}
}
}
解决方法:
设置ClientTimeout仅在将Asynchronous属性设置为true时才有用.你没做的.非托管IDirectorySearcher接口的文档更加详细.从the MSDN article开始:
The client time limit preference is useful when a client requests an asynchronous search. In an asynchronous search, the client makes a request and then proceeds with other tasks while waiting for the server to return the results. It is possible that the server can go offline without notifying the client. In this case, the client will have no notification of whether the server is still processing the query, or if it no longer live. The client time limit preference gives the client some control of situations like this.
请注意,当您使用托管类时,这种“某种情况控制”并不完美. SearchResultCollection包装类实际上并没有为您提供一种干净的异步搜索方式,它没有“BeginMoveNext”方法来迭代下一个结果. “继续其他任务”的角度是理论上的.最好不要使用该属性.
内容总结
以上是互联网集市为您收集整理的c# – 如何在使用DirectorySearcher时确定ClientTimeout全部内容,希望文章能够帮你解决c# – 如何在使用DirectorySearcher时确定ClientTimeout所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。