public async Task RunAsync(INotificationHandler handler, CancellationToken token) { while (!token.IsCancellationRequested) { // get notifications var hitung = await GetCountAsync(); foreach (var data in hitung) { if (count != Convert.ToDouble(data.Jumlah)) { // get notifications var notification = await GetNotificationsAsync(); // notify handler handler.OnNewNotifications(notification); // wait for 10 seconds await Task.Delay(TimeSpan.FromSeconds(1)); count = Convert.ToDouble(data.Jumlah); } else { count = Convert.ToDouble(data.Jumlah); } } } }
public async Task RunAsync(INotificationHandler handler, CancellationToken token) { while (!token.IsCancellationRequested) { // get notifications var notifications = await GetNotificationsAsync(); // notify handler handler.OnNewNotifications(notifications); // wait for 10 seconds await Task.Delay(TimeSpan.FromSeconds(10)); } }