/// <summary> /// Start new /// </summary> /// <param name="delay"></param> /// <param name="action"></param> /// <param name="scheduler"></param> /// <returns></returns> public static CancellableTask StartNew(TimeSpan delay, Action action = null, TaskScheduler scheduler = null) { var task = new CancellableTask(action); task.Start(delay, scheduler); return(task); }
/// <summary> /// Start new /// </summary> /// <param name="action"></param> /// <param name="delay"></param> /// <param name="scheduler"></param> /// <returns></returns> public static CancellableTask StartNew(Action <CancellationToken> action, TimeSpan?delay = null, TaskScheduler scheduler = null) { 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); }