November 24th, 2026
likeintriguing3 reactions

What happens to entries in the CoreApplication Properties when the source apartment shuts down?

Commenter Luca Bacci observed:

Don’t know why, but last I tried the COM static store (runtime class “Windows.ApplicationModel.Core.CoreApplication”) was accessible from an unpackaged, Win32 application. It also seems to tie entries to the originating apartment lifetime (namely: the apartment from which the property is added). Can you shed some light?

First part first: The COM static store is available to all applications.

This API is supported in Universal Windows Platform apps only, except for the Properties property, which is always available.

Okay, now the second part: What happens to the entries in the CoreApplication Properties when the source apartment shuts down?

Nothing.

Nothing happens to them. They are still there. Here’s a demonstration:

#include <stdio.h>
#include <winrt/Windows.ApplicationModel.Core.h>
#include <winrt/Windows.Foundation.Collections.h>

int main()
{
    winrt::init_apartment(winrt::apartment_type::single_threaded);

    std::thread t([] {
        winrt::init_apartment(winrt::apartment_type::single_threaded);
        winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().
            Insert(L"meow", winrt::box_value(1));
        winrt::uninit_apartment();
        });

    t.join();

    auto value = winrt::unbox_value<int>(
        winrt::Windows::ApplicationModel::Core::CoreApplication::Properties().
        Lookup(L"meow"));
    
    printf("Got the value %d\n", value);
    winrt::uninit_apartment();
    return 0;
}

After initializing COM on the main thread, we create a secondary thread, on which we also initialize COM in single-threaded mode, add a value to the Core­Application.Properties called "meow" with a value of 1, and then uninitialize the apartment.

Back on the main thread, we wait for that to finish, and then go to the Core­Application.Properties and ask for the "meow" value, and hey, there it is!

So the entries in Core­Application.Properties do not expire at the expiration of the apartment that added them. But, they do expire when the last apartment shuts down, because that’s when COM shuts down for the entire process.

Next time, we’ll investigate what Luca observed.

Topics

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

1 comment

Sort by :
  • Michael Taylor 4 days ago

    The title of this post seems incorrect. “When happens to entries in the CoreApplication Properties when the source apartment shuts down?” Should that be “What happens to…”?