private async Task ValidateCache() { if (IsCacheValid) { return; } try { _cachedItems = await _wrappedReader.GetPeopleAsync(); _dataDateTime = DateTime.Now; } catch { _cachedItems = new List <Person>() { new Person() { GivenName = "No Data Available", FamilyName = string.Empty, Rating = 0, StartDate = DateTime.Today, } }; InvalidateCache(); } }
public Task <ViewResult> WithTask() { ViewData["Title"] = "Using Task"; ViewData["RequestStart"] = DateTime.Now; Task <IReadOnlyCollection <Person> > peopleTask = reader.GetPeopleAsync(); Task <ViewResult> resultTask = peopleTask.ContinueWith(task => { if (task.IsFaulted) { var errors = task.Exception !.Flatten().InnerExceptions; return(View("Error", errors)); } IReadOnlyCollection <Person> people = task.Result; ViewData["RequestEnd"] = DateTime.Now; return(View("Index", people)); }); return(resultTask); }
public async Task <List <Person> > GetPeopleAsync() { try { return(await _wrappedReader.GetPeopleAsync()); } catch (Exception ex) { await _logger?.LogException(ex); throw; } }
public async Task <List <Person> > GetPeopleAsync() { _retryCount++; try { var people = await _wrappedReader.GetPeopleAsync(); _retryCount = 0; return(people); } catch (Exception) { if (_retryCount >= 3) { throw; } await Task.Delay(_retryDelay); return(await this.GetPeopleAsync()); } }
public async Task RefreshPeople() { People = await Reader.GetPeopleAsync(); }