Sorry if the title is a bit nondescript, I couldn’t really word it right.
Basically, what I have is the following scenario:
I have a user-interface (WinForm) that allows users to pick multiple files to download, and then hit the “Download” button to commence downloading. All the downloads are processed asynchronously to avoid locking the form. However, while I don’t want the form to lock up with a “Not Responding” message, I also don’t want the user to be able to modify form fields while the download is running.
Ideally, I wanted to spawn a modal dialog which let’s the user know the state of the download (i.e similar to firefox, except with a modal dialog). This kills 2 birds with one stone as it allows the user to get a good view of the download progress, while also stopping the user interacting with the parent form while the dialog is active.
However, to properly give the user an idea of the download progress I’d need to update the dialog during runtime. This is where I’ve hit a wall. My current idea is to expose some public methods of my dialog class to send it updates when files complete, and call them from within the background download thread (with proper delegates to update controls, etc)
I’m pretty sure this would work as I want, but I was just wondering if there are any more elegant solutions to this problem. Don’t feel limited to the dialog approach, I’m open to all approaches that may offer a better alternative.
Cheers,
J
Alternative 1
You may consider using a BackgroundWorker, it will take of setting a new thread to do the job and provides an event based mechanism to report progress and also a method to request to cancel the operation (it is up to you if you want to use that).
To set the task for your BackgroundWorker you will need to attach a handler to the event
DoWorkand then callRunWorkerAsync().Alternative 2
Another alternative is to use
IObservable<T>to create a mechanism to respond to the progress of the download, then you could do the binding with using Reactive.I take you are new to Reactive. In that case, this is best introduction available (in my opinion):
http://channel9.msdn.com/Blogs/codefest/DC2010T0100-Keynote-Rx-curing-your-asynchronous-programming-blues
If you had the freedom to not disable the UI… You could have the progress reported at a status bar, or dedicate a secondary form (which you could let the user close and get back with a NotifyIcon) where you have the current and any pending works.