Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-25
6
Medium Priority
?
262 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

610 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