diff --git a/BizHawk.Common/Util.cs b/BizHawk.Common/Util.cs
index fce648df50..26963623e8 100644
--- a/BizHawk.Common/Util.cs
+++ b/BizHawk.Common/Util.cs
@@ -24,6 +24,20 @@ namespace BizHawk.Common
}
}
+ ///
+ /// Waits 250ms for a file to vanish. Returns whether it succeeded
+ ///
+ public static bool TryWaitForFileToVanish(string path)
+ {
+ for (int i = 0; i < 25; i++) //250ms
+ {
+ if (!File.Exists(path))
+ return true;
+ System.Threading.Thread.Sleep(10);
+ }
+ return false;
+ }
+
///
/// Tries to moves `pathWant` out of the way to `pathBackup`, delaying as needed to accomodate filesystem being sucky.
/// `pathWant` might not be removed after all, in case it's snagged by something.
@@ -47,8 +61,11 @@ namespace BizHawk.Common
}
//deletes are asynchronous, need to wait for it to be gone
- while (File.Exists(pathBackup))
- System.Threading.Thread.Sleep(10);
+ if(!TryWaitForFileToVanish(pathBackup))
+ {
+ //gave up waiting for existing backup to be gone. the whole thing's a total loss
+ return false;
+ }
try
{
@@ -63,10 +80,7 @@ namespace BizHawk.Common
//hmm these might be asynchronous too
//wait for the move to complete, at least enough for pathWant to be cleared up
- while (File.Exists(pathWant))
- System.Threading.Thread.Sleep(10);
-
- return true;
+ return TryWaitForFileToVanish(pathWant);
}
public static bool IsPowerOfTwo(int x)