Reputation: 180
I need to run a method that returns IAsyncOperation synchronously. Any ideas?
Upvotes: 3
Views: 1256
Reputation: 108
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
}
Upvotes: 5