title: How do you cancel an async operation in C++/CX from C#
body: <p>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:</p>
  
  <p>From C#:</p>
  
  <pre><code>var tcs = new CancellationTokenSource();
  tcs.Cancel();
  var class1 = new MyClass();
  try
  {
      var asyncOp = await class1.DoSomeTaskAsync().AsTask(tcs.Token);
  }
  catch (OperationCanceledException oce)
  {
      //I want to get here
      Handle(oce);
  }
  </code></pre>
  
  <p>From C++: </p>
  
  <pre><code>IAsyncOperation&lt;bool&gt;^ MyClass::DoSomeTaskAsync(){
          return concurrency::create_async([](concurrency::cancellation_token ct) {
              task&lt;bool&gt; my_task([]() {
                  doSomething1();
                  if (concurrency::is_task_cancellation_requested())
                  {
                      concurrency::cancel_current_task();
                  }
                  doSomething2();
                  return false;
              }, ct);
              return my_task;
          });
      }
  </code></pre>
  
  <p>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.</p>