none
How to call Asynchronous method synchronously in Metro style apps

    Question

  • Hi 

    is there any way to call Asynchronous method synchronously in Metro style apps.


    Ravi Shankar

    Friday, June 29, 2012 4:27 AM

Answers

  • Maybe ;)

    If you are on the UI thread then you cannot and shouldn't call an asynchronous method synchronously. The reason asynchronous methods are encouraged is to prevent hanging the UI and frustrating the user.

    If you are on a worker thread then you can wait for the asynchronous task to complete with Task.Wait.

    --Rob

    Friday, June 29, 2012 8:24 PM
    Owner

All replies

  • Maybe ;)

    If you are on the UI thread then you cannot and shouldn't call an asynchronous method synchronously. The reason asynchronous methods are encouraged is to prevent hanging the UI and frustrating the user.

    If you are on a worker thread then you can wait for the asynchronous task to complete with Task.Wait.

    --Rob

    Friday, June 29, 2012 8:24 PM
    Owner
  • There are scenarios where you would like to run async methods synchronously, example: Unit testing
    Monday, September 24, 2012 8:21 PM
  • Rob, can you explain how to use task.Wait(); ? It never stops waiting in my experience. And doing task.Start() or task.RunSynchronously() before it always throws an exception.
    Monday, January 28, 2013 12:27 AM