Jump to content
  • Advertisement
Sign in to follow this  

[.net] BackgroundWorker + Exceptions

This topic is 4413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!