Repository: microsoft/PowerToys
File: src/modules/peek/Peek.FilePreviewer/Previewers/ImagePreviewer/ImagePreviewer.cs (C#)

Code before:
                    State = PreviewState.Loaded;
                }
            }
        }

        private Task<bool> LoadLowQualityThumbnailAsync()
        {
            return TaskExtension.RunSafe(async () =>
            {
                CancellationToken.ThrowIfCancellationRequested();

                if (!IsFullImageLoaded && !IsHighQualityThumbnailLoaded)
                {
                    var hr = ThumbnailHelper.GetThumbnail(Path.GetFullPath(File.Path), out IntPtr hbitmap, ThumbnailHelper.LowQualityThumbnailSize);
                    if (hr != Common.Models.HResult.Ok)
                    {
                        Debug.WriteLine("Error loading low quality thumbnail - hresult: " + hr);

                        throw new ArgumentNullException(nameof(hbitmap));
                    }

                    CancellationToken.ThrowIfCancellationRequested();

                    await Dispatcher.RunOnUiThread(async () =>
                    {
                        var thumbnailBitmap = await GetBitmapFromHBitmapAsync(hbitmap, CancellationToken);
                        Preview = thumbnailBitmap;
                    });
                }
            });
        }

        private Task<bool> LoadHighQualityThumbnailAsync()
        {
            return TaskExtension.RunSafe(async () =>
            {
                CancellationToken.ThrowIfCancellationRequested();

                if (!IsFullImageLoaded)
                {
                    var hr = ThumbnailHelper.GetThumbnail(Path.GetFullPath(File.Path), out IntPtr hbitmap, ThumbnailHelper.HighQualityThumbnailSize);
                    if (hr != Common.Models.HResult.Ok)
                    {
                        Debug.WriteLine("Error loading high quality thumbnail - hresult: " + hr);

                        throw new ArgumentNullException(nameof(hbitmap));
                    }

                    CancellationToken.ThrowIfCancellationRequested();

                    await Dispatcher.RunOnUiThread(async () =>

Review comment (suggestion):
Consider adding a `ThrowIfCancellationRequested` before doing this. There might be a delay before this actually runs on the UI thread as the dispatcher only queues the work. 

Code after:

        private Task<bool> LoadLowQualityThumbnailAsync(CancellationToken cancellationToken)
        {
            return TaskExtension.RunSafe(async () =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!IsFullImageLoaded && !IsHighQualityThumbnailLoaded)
                {
                    var hr = ThumbnailHelper.GetThumbnail(Path.GetFullPath(File.Path), out IntPtr hbitmap, ThumbnailHelper.LowQualityThumbnailSize);
                    if (hr != Common.Models.HResult.Ok)
                    {
                        Debug.WriteLine("Error loading low quality thumbnail - hresult: " + hr);

                        throw new ArgumentNullException(nameof(hbitmap));
                    }

                    cancellationToken.ThrowIfCancellationRequested();

                    await Dispatcher.RunOnUiThread(async () =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        var thumbnailBitmap = await GetBitmapFromHBitmapAsync(hbitmap, cancellationToken);
                        Preview = thumbnailBitmap;
                    });
                }
            });
        }

        private Task<bool> LoadHighQualityThumbnailAsync(CancellationToken cancellationToken)
        {
            return TaskExtension.RunSafe(async () =>
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (!IsFullImageLoaded)
                {
                    var hr = ThumbnailHelper.GetThumbnail(Path.GetFullPath(File.Path), out IntPtr hbitmap, ThumbnailHelper.HighQualityThumbnailSize);
                    if (hr != Common.Models.HResult.Ok)
                    {
                        Debug.WriteLine("Error loading high quality thumbnail - hresult: " + hr);

                        throw new ArgumentNullException(nameof(hbitmap));
                    }

                    cancellationToken.ThrowIfCancellationRequested();

                    await Dispatcher.RunOnUiThread(async () =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        var thumbnailBitmap = await GetBitmapFromHBitmapAsync(hbitmap, cancellationToken);