internal static FileInfoBase[] GetFilesWithRetry(this DirectoryInfoBase info) { return(OperationManager.Attempt(() => { return info.GetFiles(); })); }
private const int DefaultDelayBeforeRetry = 250; // 250 ms public static void Attempt(Action action, int retries = DefaultRetries, int delayBeforeRetry = DefaultDelayBeforeRetry) { OperationManager.Attempt <object>(() => { action(); return(null); }, retries, delayBeforeRetry); }
public static void Attempt(Action action, Func <bool> condition = null, int retries = 3, int delayBeforeRetry = 250) { OperationManager.Attempt <object>(() => { action(); return(null); }); }
private static void DoSafeAction(Action action) { try { OperationManager.Attempt(action); } catch { } }
private static void DoSafeAction(Action action, bool ignoreErrors) { try { OperationManager.Attempt(action); } catch { if (!ignoreErrors) { throw; } } }
// we cannot use FileSystemHelpers.DeleteFileSafe. // it does not handled IOException due to 'file in used'. private void DeleteFileSafe() { // Only clean up lock on Windows Env try { FileSystemHelpers.DeleteFile(_path); OperationManager.Attempt(() => // throws exception if file is still present TryRemovedLockFile() , 10, 250); } catch (Exception ex) { TraceIfUnknown(ex); } }