예제 #1
0
        private void LoadThumbnailImage()
        {
            Debug.Assert(_thumbnail == null);
            Debug.Assert(!_isShowingThumbnail);
            Debug.Assert(!_isShowingFullSize);
            Debug.Assert(!_isLoadingFullSize);
            Debug.Assert(!_isLoadingThumbnail);
            Debug.Assert(_thumbCancel == null);
            Debug.Assert(_fullCancel == null);

            _thumbCancel = new CancellationTokenSource();
            CancellationToken token = _thumbCancel.Token;

            _isLoadingThumbnail = true;
            GetURIStream(ThumbnailURI).ContinueWith(task =>
            {
                if (!token.IsCancellationRequested)
                {
                    Debug.Assert(_thumbCancel.Token == token);
                    _thumbCancel        = null;
                    _isLoadingThumbnail = false;
                }

                if (task.IsFaulted || token.IsCancellationRequested)
                {
                    return;
                }

                UnloadThumbnail();
                UnloadFullSize();
                _image.SetStreamSource(task.Result, Path.GetExtension(ThumbnailURI.AbsolutePath));

                _thumbnail          = task.Result;
                _isShowingThumbnail = true;
                _isShowingFullSize  = false;

                if (FullSizeURI != null)
                {
                    LoadFullSizeImage();
                }
            }, TaskContinuationOptions.ExecuteSynchronously);
        }