public static Task Interval( TimeSpan pollInterval, Action action, CancellationToken token, bool isRepeat) { return Task.Factory.StartNew( async () => { if (!isRepeat) { await Task.Delay(pollInterval.Milliseconds); action(); } else { for (; ; ) { if (token.WaitCancellationRequested(pollInterval)) break; action(); } } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
public static Task Interval(TimeSpan pollInterval, Action action, CancellationToken token) { return Task.Factory.StartNew(() => { for (; ; ) { if (token.WaitCancellationRequested(pollInterval)) break; action(); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
public static Task OnInterval(TimeSpan pollInterval, Action action, CancellationToken token, TaskCreationOptions taskCreationOptions, TaskScheduler taskScheduler) { return Task.Factory.StartNew(() => { for (;;) { if (token.WaitCancellationRequested(pollInterval)) break; action(); } }, token, taskCreationOptions, taskScheduler); }
public static Task Interval(TimeSpan pollInterval, Action action, System.Threading.CancellationToken token) { return(Task.Factory.StartNew(() => { for (; ;) { if (token.WaitCancellationRequested(pollInterval)) { break; } action(); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default)); }
public static Task Interval(TimeSpan pollInterval, Action action, CancellationToken token) { // We don't use Observable.Interval: // If we block, the values start bunching up behind each other. return Task.Factory.StartNew( () => { for (; ; ) { if (token.WaitCancellationRequested(pollInterval)) break; action(); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }