Pregunta

I'm trying to use C++/CX to create a WinRT component. I have the following code and it doesn't compile. What is wrong with it? From what I understand PPL tasks should transparently be converted to IAsyncOperation if it's a task with a result.

IAsyncOperation<Boolean>^ Class::OpAsync()
{
    return create_task([] () { return true; });
}

Error Message

error C2440: 'return' : cannot convert from 'Concurrency::task<_ReturnType>' to 'Windows::Foundation::IAsyncOperation<TResult> ^'
          with
          [
              _ReturnType=bool
          ]
          and
          [
              TResult=bool
          ]
          No user-defined-conversion operator available, or
          No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
¿Fue útil?

Solución

The create_task() function is for taking an IAsyncOperation and turning it into a task (basically, the reverse of what you're wanting).

To convert a task to an IAsyncOperation, you need to call create_async() instead.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top