private static async Task ReadFileAsync(RetryContext context) { try { using (FileStream stream = new FileStream("test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 256, true)) { byte[] buffer = new byte[4]; int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length); if (bytesRead == buffer.Length) { string text = Encoding.ASCII.GetString(buffer); Log("ReadFileAsync read '{0}'", text); context.Add("Text", text); } else { Log("ReadFileAsync read only {0} bytes.", bytesRead); } } } catch (Exception e) { Log("ReadFileAsync error: {0}: {1}", e.GetType().Name, e.Message); throw; } }
public static async Task AddAsync <TResult>(this RetryContext context, string name, Task <TResult> task) { TResult result = await task; context.Add(name, result); }