/// <summary> /// Lock around the output path. /// Delete the existing file with retries. /// </summary> public static async Task DeleteWithLock(string filePath) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } await ConcurrencyUtilities.ExecuteWithFileLockedAsync(filePath, lockedToken => { Delete(filePath); return(Task.FromResult(0)); }, // Do not allow this to be cancelled CancellationToken.None); }
/// <summary> /// Lock around the output path. /// Delete the existing file with retries. /// Move a file with retries. /// </summary> public static async Task ReplaceWithLock(Action <string> writeSourceFile, string destFilePath) { if (writeSourceFile == null) { throw new ArgumentNullException(nameof(writeSourceFile)); } if (destFilePath == null) { throw new ArgumentNullException(nameof(destFilePath)); } await ConcurrencyUtilities.ExecuteWithFileLockedAsync(destFilePath, lockedToken => { Replace(writeSourceFile, destFilePath); return(Task.FromResult(0)); }, // Do not allow this to be cancelled CancellationToken.None); }