private async Task HandleLoadArticlesFromIndexedDb() { BusyOverlayService.SetBusyState(BusyEnum.Busy); var stopwatch = new Stopwatch(); stopwatch.Start(); var result = await PersistenceService.GetAllAsync <Article>(); Articles = result.ToList(); ItemCount = Articles.Count(); stopwatch.Stop(); ProcessingTimeMs = stopwatch.ElapsedMilliseconds; BusyOverlayService.SetBusyState(BusyEnum.NotBusy); }
private async Task AddTenToPrice() { ProcessingTimeMs = 0; BusyOverlayService.SetBusyState(BusyEnum.Busy); var stopwatch = new Stopwatch(); stopwatch.Start(); // Load all articles from the DB Articles = (await PersistenceService.GetAllAsync <Article>()).ToList(); // Display in table ProcessingTimeMs = stopwatch.ElapsedMilliseconds; await Task.Yield(); StateHasChanged(); // Add price int counter = 0; foreach (var article in Articles) { article.Price += 10; if (!UiUpdates) { continue; } ItemCount = ++counter; ProcessingTimeMs = stopwatch.ElapsedMilliseconds; if ((counter % 100) == 0 || counter == Articles.Count) { StateHasChanged(); await Task.Delay(1); } } var counter2 = 0; // Update all articles in DB foreach (var article in Articles) { await PersistenceService.UpdateAsync <Article>(article); if (!UiUpdates) { continue; } ItemCount = ++counter2; ProcessingTimeMs = stopwatch.ElapsedMilliseconds; if ((counter2 % 100) == 0 || counter2 == Articles.Count) { StateHasChanged(); await Task.Delay(1); } } stopwatch.Stop(); ProcessingTimeMs = stopwatch.ElapsedMilliseconds; BusyOverlayService.SetBusyState(BusyEnum.NotBusy); }