Repository: microsoft/terminal
File: src/cascadia/WindowsTerminal/WindowThread.cpp (C++)

Code before:
// - Check if we should keep this window alive, to try it's message loop again.
//   If we were refrigerated for later, then this will block the thread on the
//   _microwaveBuzzer. We'll sit there like that till the emperor decides if
//   they want to re-use this window thread for a new window.
// Return Value:
// - true IFF we should enter this thread's message loop
// INVARIANT: This must be called on our "ui thread", our window thread.
bool WindowThread::KeepWarm()
{
    if (_host != nullptr)
    {
        // We're currently hot
        return true;
    }

    // Even when the _host has been destroyed the HWND will continue receiving messages, in particular WM_DISPATCHNOTIFY at least once a second. This is important to Windows as it keeps your room warm.
    MSG msg;
    for (;;)
    {
        if (!GetMessageW(&msg, nullptr, 0, 0))
        {
            return false;
        }
        if (msg.message == AppHost::WM_REFRIGERATE)
        {
            _UpdateSettingsRequestedToken = _host->UpdateSettingsRequested([this]() { _UpdateSettingsRequestedHandlers(); });
            // Re-initialize the host here, on the window thread
            _host->Initialize();
            return true;
        }
        DispatchMessageW(&msg);
    }
}

// Method Description:
// - "Refrigerate" this thread for later reuse. This will refrigerate the window
//   itself, and tear down our current app host. We'll save our window for
//   later. We'll also pump out the existing message from XAML, before
//   returning. After we return, the emperor will add us to the list of threads
//   that can be re-used.
void WindowThread::Refrigerate()
{
    _host->UpdateSettingsRequested(_UpdateSettingsRequestedToken);

    // keep a reference to the HWND and DesktopWindowXamlSource alive.
    _warmWindow = std::move(_host->Refrigerate());

    // rundown remaining messages before destructing the app host
    _pumpRemainingXamlMessages();
    _host = nullptr;
}

Review comment (suggestion):
```suggestion
        // We're using a single window message (WM_REFRIGERATE) to indicate both 
        // state transitions. In this case, the window is actually being microwaved. 
        if (msg.message == AppHost::WM_REFRIGERATE)
```

Code after:
// - Check if we should keep this window alive, to try it's message loop again.
//   If we were refrigerated for later, then this will block the thread on the
//   _microwaveBuzzer. We'll sit there like that till the emperor decides if
//   they want to re-use this window thread for a new window.
// Return Value:
// - true IFF we should enter this thread's message loop
// INVARIANT: This must be called on our "ui thread", our window thread.
bool WindowThread::KeepWarm()
{
    if (_host != nullptr)
    {
        // We're currently hot
        return true;
    }

    // Even when the _host has been destroyed the HWND will continue receiving messages, in particular WM_DISPATCHNOTIFY at least once a second. This is important to Windows as it keeps your room warm.
    MSG msg;
    for (;;)
    {
        if (!GetMessageW(&msg, nullptr, 0, 0))
        {
            return false;
        }
        // We're using a single window message (WM_REFRIGERATE) to indicate both
        // state transitions. In this case, the window is actually being woken up.
        if (msg.message == AppHost::WM_REFRIGERATE)
        {
            _UpdateSettingsRequestedToken = _host->UpdateSettingsRequested([this]() { _UpdateSettingsRequestedHandlers(); });
            // Re-initialize the host here, on the window thread
            _host->Initialize();
            return true;
        }
        DispatchMessageW(&msg);
    }
}

// Method Description:
// - "Refrigerate" this thread for later reuse. This will refrigerate the window
//   itself, and tear down our current app host. We'll save our window for
//   later. We'll also pump out the existing message from XAML, before
//   returning. After we return, the emperor will add us to the list of threads
//   that can be re-used.
void WindowThread::Refrigerate()
{
    _host->UpdateSettingsRequested(_UpdateSettingsRequestedToken);

    // keep a reference to the HWND and DesktopWindowXamlSource alive.
    _warmWindow = std::move(_host->Refrigerate());

    // rundown remaining messages before destructing the app host
    _pumpRemainingXamlMessages();