是否有不会停滞的GetFileAttributes替代品? (除了在线程中调用它并在超时后杀死线程外,这似乎都带来了问题)解决方案问题实际上不是GetFileAttributes.它通常仅使用一次对基础文件系统驱动程序的调用.就是那个IO停滞了.仍然,解决方案可能很简单.呼叫 CancelSynchronousIo()一秒钟后(这显然需要第二个线程,因为您的第一个线程卡在GetFileAttributes中).I'm testing the existence of a file in a remote share (on a Windows server). The underlying function used for testing is WinAPI's GetFileAttributes, and what happens is that function can take an inordinate amount of time (dozens of seconds) in various situations, like when the target server being offline, when there are rights or DNS issues, etc.However, in my particular case, it's always a LAN access, so if the file can't be accessed in less than 1 second, then it typically won't be accessible by waiting dozens of seconds more...Is there an alternative to GetFileAttributes that wouldn't stall? (apart from calling it in a thread and killing the thread after a timeout, which seems to bring its own bag of issues) 解决方案 The problem isn't GetFileAttributes really. It typically uses just one call to the underlying file system driver. It's that IO which is stalling.Still, the solution is probably easy. Call CancelSynchronousIo() after one second (this obviously requires a second thread as your first is stuck inside GetFileAttributes). 这篇关于如何避免GetFileAttributes中的网络停顿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 13:51