Repository: microsoft/PowerToys
File: src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs (C#)

Code before:
                if (viewModel.InitializeCommand.ExecutionTask.Status != TaskStatus.RanToCompletion)
                {
                    // TODO: Handle failure case
                    if (viewModel.InitializeCommand.ExecutionTask.Exception is AggregateException ex)
                    {
                        Logger.LogError(ex.ToString());
                    }

                    // TODO GH #239 switch back when using the new MD text block
                    // _ = _queue.EnqueueAsync(() =>
                    /*_queue.TryEnqueue(new(() =>
                    {
                        LoadedState = ViewModelLoadedState.Error;
                    }));*/
                }
                else
                {
                    // TODO GH #239 switch back when using the new MD text block
                    // _ = _queue.EnqueueAsync(() =>
                    _ = Task.Factory.StartNew(
                        () =>
                        {
                            var result = (bool)viewModel.InitializeCommand.ExecutionTask.GetResultOrDefault()!;

                            CurrentPage = viewModel; // result ? viewModel : null;
                            ////LoadedState = result ? ViewModelLoadedState.Loaded : ViewModelLoadedState.Error;
                        },
                        CancellationToken.None,
                        TaskCreationOptions.None,
                        _scheduler);
                }
            });
        }
        else
        {
            CurrentPage = viewModel;
            ////LoadedState = ViewModelLoadedState.Loaded;
        }
    }

    public void PerformTopLevelCommand(PerformCommandMessage message)
    {
        if (_mainListPage == null)
        {
            return;
        }

        if (message.Context is IListItem listItem)
        {
            _mainListPage.UpdateHistory(listItem);
        }

Review comment (bug):
oh noooo this was so very wrong. 

This didn't get the result of the existing async task, no. 

This started the init _again_. This time, on the UI thread. 

Code after:
                if (viewModel.InitializeCommand.ExecutionTask.Status != TaskStatus.RanToCompletion)
                {
                    // TODO: Handle failure case
                    if (viewModel.InitializeCommand.ExecutionTask.Exception is AggregateException ex)
                    {
                        Logger.LogError(ex.ToString());
                    }

                    // TODO GH #239 switch back when using the new MD text block
                    // _ = _queue.EnqueueAsync(() =>
                    /*_queue.TryEnqueue(new(() =>
                    {
                        LoadedState = ViewModelLoadedState.Error;
                    }));*/
                }
                else
                {
                    // TODO GH #239 switch back when using the new MD text block
                    // _ = _queue.EnqueueAsync(() =>
                    _ = Task.Factory.StartNew(
                        async () =>
                        {
                            // bool f = await viewModel.InitializeCommand.ExecutionTask.;
                            // var result = viewModel.InitializeCommand.ExecutionTask.GetResultOrDefault()!;
                            // var result = viewModel.InitializeCommand.ExecutionTask.GetResultOrDefault<bool?>()!;
                            var result = await viewModel.InitializeAsync();

                            CurrentPage = viewModel; // result ? viewModel : null;
                            ////LoadedState = result ? ViewModelLoadedState.Loaded : ViewModelLoadedState.Error;
                        },
                        CancellationToken.None,
                        TaskCreationOptions.None,
                        _scheduler);
                }
            });
        }
        else
        {
            CurrentPage = viewModel;
            ////LoadedState = ViewModelLoadedState.Loaded;
        }
    }

    public void PerformTopLevelCommand(PerformCommandMessage message)
    {
        if (_mainListPage == null)
        {
            return;
        }

        if (message.Context is IListItem listItem)