Repository: microsoft/PowerToys
File: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WinGet/Pages/InstallPackageCommand.cs (C#)

Code before:
            _installBanner.Message = string.Format(CultureInfo.CurrentCulture, InstallingPackage, _package.Name);
            WinGetExtensionHost.Instance.ShowStatus(_installBanner, StatusContext.Extension);

            var installOptions = WinGetStatics.WinGetFactory.CreateInstallOptions();
            installOptions.PackageInstallScope = PackageInstallScope.Any;

            installOptions.SkipDependencies = SkipDependencies;

            _installAction = WinGetStatics.Manager.InstallPackageAsync(_package, installOptions);

            var handler = new AsyncOperationProgressHandler<InstallResult, InstallProgress>(OnInstallProgress);
            _installAction.Progress = handler;

            _installTask = Task.Run(() => TryDoInstallOperation(_installAction));
        }

        return CommandResult.KeepOpen();
    }

    private async void TryDoInstallOperation<T_Operation, T_Progress>(
        IAsyncOperationWithProgress<T_Operation, T_Progress> action)
    {
        try
        {
            await action.AsTask();

            _installBanner.Message = InstallCommandState == PackageInstallCommandState.Uninstall ?
                string.Format(CultureInfo.CurrentCulture, UninstallPackageFinished, _package.Name) :
                string.Format(CultureInfo.CurrentCulture, InstallPackageFinished, _package.Name);

            _installBanner.Progress = null;
            _installBanner.State = MessageState.Success;
            _installTask = null;

            _ = Task.Run(() =>
            {
                Thread.Sleep(2500);
                if (_installTask == null)
                {
                    WinGetExtensionHost.Instance.HideStatus(_installBanner);
                }
            });
            InstallStateChanged?.Invoke(this, this);
        }
        catch (Exception ex)
        {
            _installBanner.State = MessageState.Error;
            _installBanner.Progress = null;
            _installBanner.Message = ex.Message;
            _installTask = null;
        }

Review comment (suggestion):
For line #153, I think it's better to use await Task.Delay to avoid block the whole thread?
![image](https://github.com/user-attachments/assets/06d8c97c-6b05-49e3-aea6-0bc1c0bdda75)


Code after:
            WinGetExtensionHost.Instance.ShowStatus(_installBanner, StatusContext.Extension);

            var installOptions = WinGetStatics.WinGetFactory.CreateInstallOptions();
            installOptions.PackageInstallScope = PackageInstallScope.Any;

            installOptions.SkipDependencies = SkipDependencies;

            _installAction = WinGetStatics.Manager.InstallPackageAsync(_package, installOptions);

            var handler = new AsyncOperationProgressHandler<InstallResult, InstallProgress>(OnInstallProgress);
            _installAction.Progress = handler;

            _installTask = Task.Run(() => TryDoInstallOperation(_installAction));
        }

        return CommandResult.KeepOpen();
    }

    private async void TryDoInstallOperation<T_Operation, T_Progress>(
        IAsyncOperationWithProgress<T_Operation, T_Progress> action)
    {
        try
        {
            await action.AsTask();

            _installBanner.Message = InstallCommandState == PackageInstallCommandState.Uninstall ?
                string.Format(CultureInfo.CurrentCulture, UninstallPackageFinished, _package.Name) :
                string.Format(CultureInfo.CurrentCulture, InstallPackageFinished, _package.Name);

            _installBanner.Progress = null;
            _installBanner.State = MessageState.Success;
            _installTask = null;

            _ = Task.Run(async () =>
            {
                await Task.Delay(2500).ConfigureAwait(false);

                if (_installTask == null)
                {
                    WinGetExtensionHost.Instance.HideStatus(_installBanner);
                }
            });
            InstallStateChanged?.Invoke(this, this);
        }
        catch (Exception ex)
        {
            _installBanner.State = MessageState.Error;
            _installBanner.Progress = null;
            _installBanner.Message = ex.Message;
            _installTask = null;
        }