?
Solved

WebClient Class and Error Handling (Need assistance making an app more robust

Posted on 2004-09-25
6
Medium Priority
?
261 Views
Last Modified: 2012-05-05
Hello all.  I have beem working sort of half-heartedly on a screen scraper application that downloads a given web page, extracts, formats and presents data.  I have been using the System.Net.WebClient Class to retrieve the web page like so:

Private Function GetPageHTML(ByVal URL As String) As String
    ' Retrieves the HTML from the specified URL
    Dim objWC As New System.Net.WebClient
    Return New System.Text.UTF8Encoding().GetString(objWC.DownloadData(URL))
End Function

It seems to work fairly well except if the page is unavailable or some other network error happens, the application freezes and pretty much never comes back or I get a vague pop-up telling me there was an unhandled exception.  I had done some work in PHP with CURL and it had a timeout value that prevented this but a perusal of the docs does not reveal any such abilities with this class.

So, I'm looking for a way to make a web page retrieval time out and/or return an error if there's an issue.

My forte' is really VB 6.0 so please keep that in mind as you answer.  I'm not very experienced in .NET yet but I'm learning to like it rapidly.

Setting this at 250 because I'm betting that this is an easy answer (if not we can negotiate) but I'm looking for an answer sort of quick before I don;t need it anymore. :-).  Thanks for reading.
0
Comment
Question by:lbussy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
thenrich earned 1000 total points
ID: 12162364
Couldn't you do this:

Private Function GetPageHTML(ByVal URL As String) As String
    ' Retrieves the HTML from the specified URL
    Dim objWC As New System.Net.WebClient
try    
Return New System.Text.UTF8Encoding().GetString(objWC.DownloadData(URL))
catch ex as exception
  ex.messge
end try
End Function

Trap the for whatever error you need.
0
 

Author Comment

by:lbussy
ID: 12162549
Probably however that only tells the app about an error.  I can't set the timeout value (and prevent the app from hanging) without being able to do that OR thread it somehow.  The timeout havlue as it stands seems like 60 or 120 seconds.
0
 
LVL 5

Expert Comment

by:thenrich
ID: 12162674
what do you mean by OR thread?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lbussy
ID: 12162700
Okay, the URL is pulled down triggered by a timer event.  When it tries to pull it down and it fails the timer stops, the application becomes unresponsive, sometimes has to be killed.  Other times it generates a .NET Frameork error.  If it were to pull the data in a different thread somehow or just timeout like I want (say after 10 seconds) then it would be fine.
0
 

Author Comment

by:lbussy
ID: 12188570
I'm going to close this and award the points to the only person who took the time to read and try to help.  It's not a solution to my issue but I appreciate the effort anyway.
0
 
LVL 5

Expert Comment

by:thenrich
ID: 12189093
Just sorry I couldn't help you more...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question