There is a method that accesses the server, and therefore uses approximately the following call:
public static async Task<Page> GetPageAsync(Uri url) { var webClient = new CookieClient(); await webClient.DownloadStringTaskAsync(url); return new Page(result, webClient.ResponseUri); } The method works, but it is usually used in others, and the above is as follows:
public static async Task<string> GetName(Uri uri) { var name = string.Empty; var document = new HtmlDocument(); var page = await Page.GetPageAsync(uri); document.LoadHtml(page.Content); var nameNode = document.DocumentNode.SelectSingleNode("//head/title"); return WebUtility.HtmlDecode(nameNode.InnerHtml); } The essence of the problem is GetName(uri).Result hangs silently and does nothing, when trying to call a method like this in normal code. Taska is in the WaitingForActivation state.
Can I call async methods in synchronous code, or do I need to write similar synchronous code using separate methods?
Task.Resultin a UI thread accidentally? - VladD