Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalPage.cpp (C++)

Code before:
            // To mitigate this, we're gonna wait for the UI thread to finish
            // everything it's gotta do for the initial init, and _then_ fire
            // our Initialized event. By waiting for everything else to finish
            // (CoreDispatcherPriority::Low), we let all the tabs and panes
            // actually get created. In the window layer, we're gonna cloak the
            // window till this event is fired, so we don't actually see this
            // frame until we're actually all ready to go.
            //
            // This will result in the window seemingly not loading as fast, but
            // it will actually take exactly the same amount of time before it's
            // usable.
            //
            // We also experimented with drawing a solid BG color before the
            // initialization is finished. However, there are still a few frames
            // after the frame is displayed before the XAML content first draws,
            // so that didn't actually resolve any issues.

            // Capture calling context.
            winrt::apartment_context ui_thread;
            auto weak{ get_weak() };

            // Switch to the BG thread -
            co_await winrt::resume_background();

            // Then enqueue the rest of this function for after the UI thread settles.
            co_await wil::resume_foreground(Dispatcher(), CoreDispatcherPriority::Low);

            if (auto self{ weak.get() })
            {
                _InitializedHandlers(*self, nullptr);
            }
        }
    }

    // Method Description:
    // - Show a dialog with "About" information. Displays the app's Display
    //   Name, version, getting started link, documentation link, release
    //   Notes link, and privacy policy link.
    void TerminalPage::_ShowAboutDialog()
    {
        _ShowDialogHelper(L"AboutDialog");
    }

    winrt::hstring TerminalPage::ApplicationDisplayName()
    {
        return CascadiaSettings::ApplicationDisplayName();
    }

    winrt::hstring TerminalPage::ApplicationVersion()
    {
        return CascadiaSettings::ApplicationVersion();

Review comment (suggestion):
`Dispatcher()` depends on `this` so you could capture it at the start of the function (instead of `ui_thread`).

Code after:
            //
            // To mitigate this, we're gonna wait for the UI thread to finish
            // everything it's gotta do for the initial init, and _then_ fire
            // our Initialized event. By waiting for everything else to finish
            // (CoreDispatcherPriority::Low), we let all the tabs and panes
            // actually get created. In the window layer, we're gonna cloak the
            // window till this event is fired, so we don't actually see this
            // frame until we're actually all ready to go.
            //
            // This will result in the window seemingly not loading as fast, but
            // it will actually take exactly the same amount of time before it's
            // usable.
            //
            // We also experimented with drawing a solid BG color before the
            // initialization is finished. However, there are still a few frames
            // after the frame is displayed before the XAML content first draws,
            // so that didn't actually resolve any issues.

            auto weak{ get_weak() };

            // Switch to the BG thread -
            co_await winrt::resume_background();

            if (auto self{ weak.get() })
            {
                // Then enqueue the rest of this function for after the UI thread settles.
                co_await wil::resume_foreground(self->Dispatcher(), CoreDispatcherPriority::Low);
            }
            else
            {
                // We don't exist anymore? Well, we probably don't need to fire
                // off an Initialized event then...
                co_return;
            }

            if (auto self{ weak.get() })
            {
                self->_InitializedHandlers(*self, nullptr);
            }
        }
    }

    // Method Description:
    // - Show a dialog with "About" information. Displays the app's Display
    //   Name, version, getting started link, documentation link, release
    //   Notes link, and privacy policy link.
    void TerminalPage::_ShowAboutDialog()
    {
        _ShowDialogHelper(L"AboutDialog");
    }