Popular Articles
Last viewed:
- Fix for Firefox click() event issue
- Tutorial for Configuring Silverlight 4, Entity Framework and WCF RIA Services in Separate Component Assemblies (DLL’s)
- Connecting to SQL Server, Oracle, and MySQL with Database or Windows Authentication
- SQL Server Log File (AKA LDF file) is huge - reduce size
- C# Free Component to Generate PDF - Convert HTML to PDF
- Global.asax Events in IIS 6 and IIS 7 for Static Resources
Recent comments
- Awsome!!
7 hours 6 min ago - C# insert image
21 hours 59 min ago - jkll
3 days 10 hours ago - Thank You
4 days 9 hours ago - Another approach
6 days 10 hours ago - Issue
1 week 25 min ago - thanks
1 week 11 hours ago - Calendar date time
1 week 16 hours ago - Nice Explanation
1 week 20 hours ago - ramya
1 week 3 days ago

Catching download errors
There are a couple of ways to do this. If you attempt to download a file that does not exist (invalid URL) or that may have a connection drop/timeout, then there can be an exception thrown here.
If you want the code to prompt the user and let them retry, then put a try/catch block around the code in the background worker DoWork method. When the exception is thrown, allow them to restart the download with a dialog or other message box.
If you want to abort the operation, then you don't have to do anything because the background worker already handles exception packaging across threads for you. Just let the exception get thrown. Then in the background worker RunWorkerCompleted() method, you can get the result by checking the "e" RunWorkerCompletedEventArgs parameter. Check if the Error property is = null or not. If it is not null, then there will be the exception which you can display to the user there.