private static async void InitAnimationAsync(Image image, Stream stream, RepeatBehavior repeatBehavior, int seqNum) { if (!AnimationBehavior.CheckDesignMode(image, null, stream)) { return; } try { Animator async = await Animator.CreateAsync(image, stream, repeatBehavior); AnimationBehavior.SetAnimatorCore(image, async); if (AnimationBehavior.GetSeqNum((DependencyObject)image) != seqNum) { async.Dispose(); } else { AnimationBehavior.OnLoaded(image); } } catch (Exception ex) { AnimationBehavior.OnError(image, ex, AnimationErrorKind.Loading); } }
private static void ClearAnimatorCore(Image image) { Animator animator = AnimationBehavior.GetAnimator((DependencyObject)image); if (animator == null) { return; } animator.Dispose(); AnimationBehavior.SetAnimator((DependencyObject)image, null); }
private static async void InitAnimationAsync(Image image, Uri sourceUri, CancellationToken cancellationToken, RepeatBehavior repeatBehavior, int seqNum) { if (!AnimationBehavior.CheckDesignMode(image, sourceUri, null)) { return; } try { // ISSUE: reference to a compiler-generated field Animator.DownloadProgressChanged += AnimationBehavior.DownloadProgressChanged; Animator async = await Animator.CreateAsync(image, sourceUri, cancellationToken, repeatBehavior); // ISSUE: reference to a compiler-generated field Animator.DownloadProgressChanged -= AnimationBehavior.DownloadProgressChanged; if (async == null || AnimationBehavior.GetSeqNum((DependencyObject)image) != seqNum) { if (async == null) { return; } // ISSUE: explicit non-virtual call async.Dispose(); } else { AnimationBehavior.SetAnimatorCore(image, async); AnimationBehavior.OnLoaded(image); } } catch (Exception ex) { // ISSUE: reference to a compiler-generated field Animator.DownloadProgressChanged -= AnimationBehavior.DownloadProgressChanged; AnimationBehavior.OnError(image, ex, AnimationErrorKind.Loading); } }