0

I tried to copy a .bak-file to the local machine directly after the backup on the server finished.

I never had any problems with that while testing and debugging, but after deployment I got a lot of FileNotFoundExceptions.

Drasive
  • 321
  • 1
  • 20

1 Answers1

0

I figured out that, especiall if you do the backup on an other machine, the backupfile needs a little extra time to be ready.

Waiting a little before starting the moving-process solved the problem for me.

  1. Do Backup on Server
  2. WaitForFileToExist(string); (Make sure the path is right, otherwise it will of course never return)
  3. Move File

    public void WaitForFileToExist(String path) {
        while (File.Exists(path) == false) {
            System.Threading.Sleep(10);
        }
    }
Drasive
  • 321
  • 1
  • 20
  • Waiting only 3 seconds can be a problem if the same opeeration is ran on a slower machine. You should find a way that doesn't put the `Thread` to sleep. While your approach works ( for now ) its not actually the correct way. – Security Hound May 13 '13 at 16:53
  • You are right, I replaced the waiting method. This may be more save for more different cases. – Drasive May 14 '13 at 06:06
  • Its better but I would haved used a mutex for this sort of thing, using async thread, waiting until the thread to finish. – Security Hound May 14 '13 at 11:05