private async Task RunAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { Trace.TraceInformation("Working"); while (true) { var then = DateTimeOffset.UtcNow; try { Console.WriteLine("Scheduling ..."); await _scheduler.ScheduleSourcesAsync(); Console.WriteLine("Scheduled"); } catch (Exception e) { Console.WriteLine(e.ToString()); } var seconds = DateTimeOffset.UtcNow.Subtract(then).TotalSeconds; if (seconds < 30) { await Task.Delay(TimeSpan.FromSeconds(30 - seconds), cancellationToken); } } } }
private async Task RunAsync(CancellationToken cancellationToken) { // schedule every 30 seconds or so while (!cancellationToken.IsCancellationRequested) { var then = DateTimeOffset.UtcNow; await _scheduler.ScheduleSourcesAsync(); var seconds = DateTimeOffset.UtcNow.Subtract(then).TotalSeconds; if (seconds < 30) { await Task.Delay(TimeSpan.FromSeconds(30 - seconds), cancellationToken); } } }
private static void Work() { while (true) { try { Console.WriteLine("Scheduling ..."); _scheduler.ScheduleSourcesAsync().Wait(); Console.WriteLine("Scheduled"); } catch (Exception e) { Console.WriteLine(e.ToString()); } Thread.Sleep(30 * 1000); } }
private static async Task RunAsync(CancellationToken cancellationToken) { // schedule every 30 seconds or so while (!cancellationToken.IsCancellationRequested) { Console.WriteLine("Now doing it..."); var then = DateTimeOffset.UtcNow; await _scheduler.ScheduleSourcesAsync(); var seconds = DateTimeOffset.UtcNow.Subtract(then).TotalSeconds; if (seconds < 30) { Console.ForegroundColor = ConsoleColor.Cyan; await Task.Delay(TimeSpan.FromSeconds(30 - seconds), cancellationToken); Console.WriteLine("Waiting ..."); } } }