Some WinRT methods return back on a thread with apartment type APPTYPE_NA. This in turn can cause E_RPC_WRONG_THREAD when calling GetResults(). In the example code below GetToastCollectionAsync returns on a thread with apartment type APPTYPE_NA, causing the issue:
winrt::fire_and_forget Test()
{
co_await resume_background();
auto notificationManager = ToastNotificationManager::GetDefault();
ToastCollectionManager collectionManager = notificationManager.GetToastCollectionManager();
ToastCollection collection = co_await collectionManager.GetToastCollectionAsync(L"Test");
InMemoryRandomAccessStream testStream{};
auto decoder = co_await BitmapDecoder::CreateAsync(testStream);
}
Some WinRT methods return back on a thread with apartment type APPTYPE_NA. This in turn can cause E_RPC_WRONG_THREAD when calling GetResults(). In the example code below
GetToastCollectionAsyncreturns on a thread with apartment type APPTYPE_NA, causing the issue: