Skip to content

Coroutine resumption logic can cause RPC_E_WRONG_THREAD exception. #458

@jlaanstra

Description

@jlaanstra

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions