using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ips.Library.Basic { public static class CommonExceptionExtensions { public static void HandleCancelEx(this Exception source, Action handleAct, Action opCancelAct = null) { if (source == null) return; var aggex = source as AggregateException; if (aggex != null) { aggex.Flatten().Handle(ex => { HandleEx(ex, handleAct, opCancelAct); return true; }); } else { HandleEx(source, handleAct, opCancelAct); } } private static void HandleEx(Exception ex, Action handleAct, Action opCancelAct) { if (ex is OperationCanceledException) { opCancelAct?.Invoke((OperationCanceledException)ex); } else { handleAct(ex); } } } }