更快的 DirectoryExists 功能? [英] Faster DirectoryExists function?
问题描述
我用
DirectoryExists (const PathName : String);
检查是否可以从计算机访问目录.但是如果目录不存在且路径名是网络路径,即
to check if a directory is reachable from a computer or not. But if the directory does not exist and the path name is a network path, i.e.
\computer1Data
该方法需要很长时间才能返回.
the method takes a very long time to return.
必须有一种更快的方法来确定网络文件夹不可访问.或者我可以配置 DirectoryExists 在内部使用的一些超时参数(我查看了源代码,但它只是委托给在 kernel32 中定义的 GetFileAttributes)?
There must be a faster way to determine that a network folder is not reachable. Or can I configure some timeout parameter that DirectoryExists uses internally (I looked at the source code but it just delegates to GetFileAttributes which is defined in kernel32)?
有什么想法吗?
推荐答案
没有更快的方法:
当该共享不可用时,任何访问远程共享上任何内容的函数都将超时.
any function accessing anything on a remote share will timeout when that share is not available.
如果您超时的原因是自动断开共享,那么这些链接可能对您有所帮助:
If the cause of your timeouts is automatic disconnecting of shares, then these link may help you:
如果应用程序可以在没有完成检查的情况下继续运行,那么您可以将检查放在一个单独的线程中,检查完成后,您可以在 UI 中更新您的状态.
If the application can continue without the completion of the check, then you can put the check in a separate thread, and upon completion of the check, you can update your status in the UI.
请注意,当您尝试多线程方式时,您必须证明您的代码没有竞争条件和内存泄漏.超时与异常相结合通常会使这成为一项艰巨的任务.
Be aware that when you try a multi-threading way, that you have to disprove your code is free of race-conditions and memory leaks. Time-outs in combination with exceptions usually make that a hard task.
这篇关于更快的 DirectoryExists 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!