I have an httpClient with async() methods, I need to use in sync methods called from the GUI thread. I cannot use the .Result property of the task because it causes a deadlock and freezes the GUI.
I have a solution with launching a new thread pool thread and executing an async method in it:
Task.Run(async () => { ApiInfo = await _apiClient.Get($"{Url}"); }).Wait();
This works, but because I'm new to async programming - I'm not sure if it's the preferred way for my situation?
No comments:
Post a Comment