设置当前目录超时

发布于 2024-07-26 11:51:03 字数 112 浏览 1 评论 0原文

如果网络速度减慢导致目录在一段时间内无法访问,SetCurrentDirectory() 是否可能超时? (大约 15-30 秒......?)

如果是的话,超时可以配置吗?在哪里可以设置?

Is it possible for the SetCurrentDirectory() to timeout if there is network slowdown preventing the directory from being accessed for some length of time? (In the order of 15-30 seconds...?)

If so is the timeout configurable and where can it be set?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愛上了 2024-08-02 11:51:03

以下程序尝试将 SetCurrentDirectory 设置为不存在的目录失败,错误为 0x2,即 ERROR_FILE_NOT_FOUND。 由于 SetCurrentDirectory 正在对目录进行一些验证,因此您可能会在网络连接速度较慢时超时。

#include <windows.h>
#include <stdio.h>

int __cdecl main()
{

   if (SetCurrentDirectory(L"C:\\Invalid") == 0)
   {
        printf("0x%x", GetLastError());
   }

   return 0;
}

The following program that tries to SetCurrentDirectory to a non-existent directory fails with error of 0x2, which is ERROR_FILE_NOT_FOUND. Since SetCurrentDirectory is doing some validation on the directory, you can expect to to timeout on a slow network connection.

#include <windows.h>
#include <stdio.h>

int __cdecl main()
{

   if (SetCurrentDirectory(L"C:\\Invalid") == 0)
   {
        printf("0x%x", GetLastError());
   }

   return 0;
}
疯到世界奔溃 2024-08-02 11:51:03

您可以尝试在单独的线程中设置当前目录,并等待它完成一段合理的时间。 由于当前目录设置是针对每个进程的,因此从另一个线程调用 SetCurrentDirectory 仍然可以完成这项工作。 当然,您必须考虑如果集合花费的时间比您愿意等待的时间长,但在主线程移动到集合上之后确实完成了,会发生什么。

话虽如此,我尝试避免使用当前目录,而不是打开文件选择对话框等。 由于进程是全局的,因此在多线程环境中它是不可信的。 如果可能的话,使用完整路径会更好。

You can try setting the current directory in a separate thread, and wait for it to complete only for a reasonable period of time. Since the current directory setting is per process, calling SetCurrentDirectory from another thread would still do the job. You do have to consider, of course, what should happen if the set took longer than you were willing to wait, but after the main thread moved on the set has indeed completed.

Having that said, I try to avoid using a current directory for reasons other than opening a file selection dialog or so. Being process global, in a multithreaded environment it cannot be trusted. Using full paths are better when possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文