3

I need to run a method that returns IAsyncOperation synchronously. Any ideas?

1 Answers1

4

It would be better to convert IAsyncOperation to Task. Call AsTask() extension for that case. Then just Wait() its end and fetch the results. In that case your code should look like:

//Your async operation
public IAsyncOperation<object> Operation()
{
    //Doing some important stuff
}

public void Initialize()
{
    Task op = Operation().AsTask();
    op.Wait();
    object results = op.Result;    //Here's our result
}
xfox111
  • 98
  • 8