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

Code before:
            // 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();

            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");
    }


Review comment (bug):
I'd suggest just storing the dispatcher in the beginning as
```cpp
const auto dispatcher = Dispatcher();
```

Seems like a more hassle free solution to me.
Also: Do you mind removing the `winrt::apartment_context` instantiation?

Finally there's the option to drop all of the coroutine stuff and write this:
```cpp
Dispatcher().RunAsync(CoreDispatcherPriority::Low, [weak = get_weak()]() {
    if (auto self = weak.get())
    {
        self->_InitializedHandlers(*self, nullptr);
    }
});
```

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");
    }

    winrt::hstring TerminalPage::ApplicationDisplayName()