Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async method in Global.asax

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

like image 313
mberube.Net Avatar asked Apr 28 '14 15:04

mberube.Net


Video Answer


1 Answers

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();
like image 142
Martin Costello Avatar answered Oct 10 '22 10:10

Martin Costello