[.net] BackgroundWorker + Exceptions

Started by
2 comments, last by orbano 17 years, 12 months ago
Hi! I could not find any info about this topic on msnd. I sart a modal form from my main form, which uses a backgroundworker for ftp download (currently simply calling DatSet.ReadXml() for an ftp uri, but im planning to use FtpWebRequest). I have two questions: 1. What happens, if an exception occurs in the BackgroundWorker that is not handled locally? Can i catch it from the main thread? I call the form.ShoDialog() inside a try block, and i catch every exception coming up from the download form 2. How can i display the download progress? I bet i can do nothing with the DataSet.ReadXml, but what about the FtpWebRequest.GetResponse? First i thought, the stream it returns is only a handle to the remote resource, but this damned one downloads the whole file to the local machine before i can begin reading it! Displaying a Marquee while downloading is so so so lame! :'( Please help! Thanks in advance!
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
Advertisement
When an exception occurs, it goes up the call stack until something catches it. If you don't catch it, the Windows function that called your main/WinMain will catch it. I'm pretty sure there is no way for an exception to find its way from your modal thread back to the main program thread. And if there is, it must be horrible practice to do so. If the modal thread does not handle the exception, I'm guessing the thread will be terminated by Windows and your main program thread will be unaltered.

And as for displaying the download progress, no clue. Read up (google) on the class and include you are using and see what methods it supports.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Quote:Original post by orbano
1. What happens, if an exception occurs in the BackgroundWorker that is not handled locally? Can i catch it from the main thread? I call the form.ShoDialog() inside a try block, and i catch every exception coming up from the download form

The documentation states:

If the operation raises an exception that your code does not handle, the BackgroundWorker catches the exception and passes it into the RunWorkerCompleted event handler, where it is exposed as the Error property of System.ComponentModel.RunWorkerCompletedEventArgs.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
thanks! any advise about ftp? :)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin

This topic is closed to new replies.

Advertisement