views:

148

answers:

2

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?

A: 

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;
}
Michael
A: 

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.

eran
"... I try to avoid using a current directory ..." I strongly agree with this for many reasons
steelbytes