Reputation: 217
I'm working on a WPF download manager which should support downloading multiple files at the same time through HTTP, adding a new download, pause/resume, displaying and updating each download process information (filename, size, download percentage, time left...) in a DataGrid, displaying progress in a ProgressBar and a bunch of other stuff.
So, the idea is to use a separate thread for each download process, and be able to dynamically create/cancel threads. What is the best way to accomplish this? Using a BackgroundWorker, ThreadPool?
Upvotes: 2
Views: 2494
Reputation: 46018
I would just use Thread
directly and keep the references to all the treads that I create.
Upvotes: 0
Reputation: 1039438
The WebClient XXXAsync methods such as DownloadFileAsync
already provide you with asynchronous versions of all methods that allow you to perform the HTTP requests on separate threads. They are also C# 5.0 async ready.
Since this is a WPF application you should ensure that you are modifying the UI controls only on the main UI thread using the Dispatcher.BeginInvoke method.
Upvotes: 6