Environment: ASP.NET MVC 5, SQL Server
Here is my method that returns current user's profile from the database:
public static ProfileModel getCurrentProfile(HttpContextBase ctx) {
User user = AccountController.getUser(ctx);
Task<ProfileModel> model = ProfileModel.getValue(user.UserID);
model.Wait();
return model.Result;
}
Upon execution, model.Wait() just hangs up.
I have read several articles about deadlocks and using ConfigAwait(false) for such situations. However, there would be lot of places I would need to call this method. I am thinking if I fix it the right way, I may be able to avoid ConfigAwait() calls altogether.
Here is how I am using the method in my index.cshtml file:
Members.Models.ProfileModel userModel = HomeController.getCurrentProfile(Context);
Html.RenderPartial("_PartialPublicProfile", userModel);
File _PartialPublicProfile requires ProfileModel instance to be passed in. Is it possible to pass in Task<ProfileModel> instance as a parameter?
Or, is there a better way to solve the problem? Regards.
getCurrentProfilein the action?