UI Thread blocked in C# WPF App during Async Download

前端 未结 1 1787
孤独总比滥情好
孤独总比滥情好 2021-01-23 00:46

I have the following basic WPF app, where I want the content displayed in the text box. However, when I click on the button, the UI thread seems to be blocking. I am not sure wh

相关标签:
1条回答
  • 2021-01-23 01:37

    This shouldn't block the UI thread, and the technique is correct.

    However, just because a method is Async, and returns a Task<T>, doesn't guarantee that the entire method (or any of it) will run asynchronously.

    In the case of WebClient, the control won't return to the caller until after the request has been completely prepared and started. With WebClient, I believe the URI preparation, including all of the DNS lookups, can happen synchronously and is required before the asynchronous portion (the actual request) begins, which can cause a delay before the request returns.

    0 讨论(0)
提交回复
热议问题