I need to run a method that returns IAsyncOperation synchronously. Any ideas?
Asked
Active
Viewed 1,133 times
3
-
2http://stackoverflow.com/questions/5095183/how-would-i-run-an-async-taskt-method-synchronously – Mauro Sampietro Aug 12 '16 at 13:36
1 Answers
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