Question

I have to call some async methods in the Application_PostAcquireRequestState method of my Global.asax (these methods comes from a library and there's no equivalent sync method for these operations). I want to be sure this async code complete before continuing with my page process because some security parameters are set with the result of that async call.

What will be the proper way to make this work without creating deadlocks ?

Thanks

Was it helpful?

Solution

Just call the Result property of the Task that the *Async() methods return, for example.

var result = BarAsync().Result;

If the methods return Task rather than Task<T>, use Wait():

BarAsync().Wait();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top