Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Processor
- {
- public void CopyData() =>
- CopyData(Try.Slow);
- public void CopyData(Try loop) =>
- loop.Execute(() =>
- File.Copy(@"ca.txt", @"c:b.txt"));
- }
- public abstract class Try
- {
- public static Try Repeat(params int[] delays) => new Repeat(delays);
- public static readonly Try Never = Repeat();
- public static readonly Try Once = Repeat(0);
- public static readonly Try Slow = Repeat(0, 500, 1500, 4500, 12000);
- public static readonly Try Fast = Repeat(0, 50, 150, 450, 1200);
- public abstract void Execute(Action action);
- }
- class Repeat : Try
- {
- IReadOnlyList<int> Delays { get; }
- public Repeat(params int[] delays)
- {
- Delays = delays;
- }
- public override void Execute(Action action)
- {
- for(int i=0; i< Delays.Count; i++)
- try
- {
- Thread.Sleep(Delays[i]);
- action();
- return;
- }
- catch
- {
- if (i == Delays.Count - 1)
- throw;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement