public static IEnumerable <T> WithProgress <T>(this IEnumerable <T> src, Func <IProgress> progressSelector, TimeSpan?updatePeriod = null) { var progress = progressSelector(); progress.Start(); var current = new Boxed(0); var actualUpdatePeriod = updatePeriod ?? TimeSpan.FromSeconds(1); var timer = new Timer(o => progress.Update((int)current.Read()), null, actualUpdatePeriod, actualUpdatePeriod); try { foreach (var i in src) { current.Increment(); yield return(i); } } finally { timer.Dispose(); } progress.Update((int)current.Read()); }