Semaphore timeout period has expired

Tim picture Tim · Sep 10, 2012 · Viewed 20.8k times · Source

I have a simple C# program that copies files from one network share to another. The program just threw a "The semaphore timeout period has expired" error. I've never seen this before and I'm kind of confused as to what it is.

The code is pretty simple: (srcPath and destPath are read from configuration settings)

DirectoryInfo di = new DirectoryInfo(srcPath);

        try
        {

            FileInfo[] files = di.GetFiles();

            foreach (FileInfo fi in files)
            {
                if(!(fi.Name.Contains("_desc")))
                {
                    File.Copy(fi.FullName, destPath + fi.Name, true);
                }
            }
        }
        catch (Exception xx)
        {
            SendMail(xx.Message, xx.StackTrace);
        }
        finally
        {

        }

Answer

Jake1164 picture Jake1164 · Sep 10, 2012

This tends to be a generic error message and is probably related to three possibilities:

  1. Connection related. Check your network cables, USB Connections / cables, reset the usb hub, network switches..etc.

  2. Check for file names that are too long, or paths that are too long.

  3. Hard drive related. Check you have enough free space and that the drive has no errors and is not fragmented.

EDIT: Added hard drive.