I'm using WebClient.DownloadFile to download a single file at a time from a web server, however, I want to know if by "The thread is blocked" developers mean that the application won't be responsive?
I tried using WebClient.DownloadFileAsync but it doesn't work like DownloadFile works, please clarify, and I can't tell because I'm downloading files off my network, so it pretty much downloads instantly, thanks in advance.
PS: Yes I tried googling and reading, couldn't find the answer I need.
Edit:
WebClient.DownloadFileAsync
ends with "Async" but doesn't return a task. It's part of theEvent-based Asynchronous Pattern
so my answer isn't relevant. This one is: You need to subscribe toWebClient.DownloadFileCompleted
event to know when the async operation completed. For example:Original Answer:
WebClient.DownloadFileAsync
returns a task you need to await. like so:DownloadFileAsync
is fires an asynchronous operation and returns a task that will complete when the operation ended.await
means waiting for that task to end in an asynchronous way, so the code after it will run when you have the result ofDownloadFileAsync
.The synchronic
DownloadFile
will block the thread that called it. If it's the UI thread, then yes... your app won't be responsive. If it isn't the UI thread, then it will still be responsive but it will be less scalable (meaning it uses threads to wait instead of doing work, so your application as a whole can do less with the same amount of threads)