*
This commit is contained in:
1 parent
0ff787c5d9
commit
27e650d698
2 files changed
+4
-3
No files matched your search
@@ -103,7 +103,8 @@ public static class DirectoryUtils {
|
|||||||
// 同一磁盘剪切,直接调用 Move(这只修改文件夹名,效率更高)
|
// 同一磁盘剪切,直接调用 Move(这只修改文件夹名,效率更高)
|
||||||
Logger.Trace($"剪切文件夹到同一磁盘:{sourceFolder} → {destFolder}");
|
Logger.Trace($"剪切文件夹到同一磁盘:{sourceFolder} → {destFolder}");
|
||||||
DirectoryUtils.Delete(destFolder); // Move 要求此前不存在对应文件夹
|
DirectoryUtils.Delete(destFolder); // Move 要求此前不存在对应文件夹
|
||||||
Directory.Move(PathUtils.ForApi(sourceFolder), PathUtils.ForApi(destFolder));
|
ResilientUtils.RetryOn<IOException>(()
|
||||||
|
=> Directory.Move(PathUtils.ForApi(sourceFolder), PathUtils.ForApi(destFolder)));
|
||||||
} else {
|
} else {
|
||||||
// 不同磁盘,必须先复制再删除,这就是我们傻逼微软
|
// 不同磁盘,必须先复制再删除,这就是我们傻逼微软
|
||||||
Logger.Trace($"剪切文件夹到不同磁盘:{sourceFolder} → {destFolder}");
|
Logger.Trace($"剪切文件夹到不同磁盘:{sourceFolder} → {destFolder}");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
public static class ResilientUtils {
|
public static class ResilientUtils {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在抛出异常时,延迟并自动重试。
|
/// 在抛出任意异常时,延迟并自动重试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Retry(Action action, int maxAttempts = 2, int delayMs = 200, [CallerMemberName] string caller = "")
|
public static void Retry(Action action, int maxAttempts = 2, int delayMs = 200, [CallerMemberName] string caller = "")
|
||||||
=> RetryOn<Exception>(action, maxAttempts, delayMs, caller);
|
=> RetryOn<Exception>(action, maxAttempts, delayMs, caller);
|
||||||
@@ -13,7 +13,7 @@ public static class ResilientUtils {
|
|||||||
=> RetryOn<TException, object?>(() => { action(); return null; }, maxAttempts, delayMs, caller);
|
=> RetryOn<TException, object?>(() => { action(); return null; }, maxAttempts, delayMs, caller);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在抛出异常时,延迟并自动重试。
|
/// 在抛出任意异常时,延迟并自动重试。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Retry<TOut>(Func<TOut> func, int maxAttempts = 2, int delayMs = 200, [CallerMemberName] string caller = "")
|
public static void Retry<TOut>(Func<TOut> func, int maxAttempts = 2, int delayMs = 200, [CallerMemberName] string caller = "")
|
||||||
=> RetryOn<Exception, TOut>(func, maxAttempts, delayMs, caller);
|
=> RetryOn<Exception, TOut>(func, maxAttempts, delayMs, caller);
|
||||||
|
|||||||
Reference in new issue
Block a user