public static CancellableTask StartNew(TimeSpan delay, Action?action = null, TaskScheduler?scheduler = default) { var task = new CancellableTask(action); task.Start(delay, scheduler); return(task); }
public static CancellableTask StartNew(Action <CancellationToken> action, TimeSpan?delay = null, TaskScheduler?scheduler = default) { var ts = new CancellationTokenSource(); var token = ts.Token; var task = new CancellableTask(() => action(token), token) { TokenSource = ts }; task.Start(delay ?? TimeSpan.Zero, scheduler); return(task); }