protected virtual async Task ForEachAsync(Func <T, int, Task <bool> > func) { var i = 0; foreach (var item in Items) { try { var shouldContinue = await func.Invoke(item, i); if (!shouldContinue) { break; } } catch (Exception ex) { var args = new CompositeExceptionEventArgs(ex, i); OnFaulted(args); if (!args.Handled) { throw; } } finally { i++; } } }
protected virtual void OnFaulted(CompositeExceptionEventArgs e) { var handler = Faulted; if (handler != null) { handler(this, e); } }