using System; using System.Threading; using System.Threading.Tasks; namespace AyaNova.Util { internal static class TaskUtil { /// ///Usage: ///await WithTimeoutAfterStart(ct => SomeOperationAsync(ct), TimeSpan.FromMilliseconds(n)); /// public static async Task WithTimeoutAfterStart(Func operation, TimeSpan timeout) { //https://stackoverflow.com/a/23478628/8939 var source = new CancellationTokenSource(); var task = operation(source.Token); source.CancelAfter(timeout); await task; } }//eoc }//eons