private async void OnRefreshRequested(object sender, RefreshRequestedEventArgs args) { using (args.GetDeferral()) { await Task.Delay(2000); _list.Insert(0, Contact.GetContactsGrouped(1)[0]); } }
private async Task StartLoadingAnimationAndRequestRefreshAsync(Action completed) { // Create a short delay to allow the expression rotation animation to smoothly transition // to the new keyframe animation. await Task.Delay(100); _refreshIconVisual.StartAnimation("RotationAngleInDegrees", _loadingAnimation); // When using the event... if (RefreshRequested != null) { var e = new RefreshRequestedEventArgs(new DeferralCompletedHandler(completed)); RefreshRequested.Invoke(this, e); } // When using the command... if (RefreshCommand != null) { try { _cts?.Cancel(); _cts = new CancellationTokenSource(); _pendingRefreshTask = DoCancellableRefreshTaskAsync(_cts.Token); await _pendingRefreshTask; } catch (OperationCanceledException) { } if (_cts != null && !_cts.IsCancellationRequested) { completed(); } } }