Asked by:

How do you cancel an async operation in C++/CX from C#

Question

I'm trying to cancel an operation that is written in C++/CX from C#. Despite the fact I wrote both pieces of code I can't get the operation to cancel properly when awaiting it from the C# side. Here's an example:

The problem seems to be that passing in the token into the AsTask extension method does nothing when calling a task across the ABI. When debugging the C++ side both the ct and the is_task_cancellation_requested() function indicate that a cancellation
has not been requested.

NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
objects and unknown namespaces.