dcsimg
Results 1 to 5 of 5

Thread: "WebClient" very slow on initial request

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    11

    "WebClient" very slow on initial request

    Hi all.

    I'm new here.
    I am looking for a great VB.NET forum for support on the newest 2010 version.

    I have a large project currently Compiled on the NET 4.0.

    I have also ran it on 3.4, 2.0, and, 1.1..

    I am trying to read a text file on a server which has ONE line about 12 charters long.

    On the initial request to read the file I have about a 7 second delay before there is any further action. All subsequent request are instant considering I do not close the program.

    I have searched and searched Google and read some older post from this site. Most refer to the proxy setting and say setting the proxy to NULL will fix this issue. Well we all know that this cannot be down in the newer version of .NET. I did not have this issue in .NET 1.1 using the same code.

    Can anyone here tell me how to make the webclient avoid this delay the first time it hits the server?-

    ========= VB Code Below which is turned off for me =======
    Dim wc As New WebClient
    Dim s As String = ""
    s = wc.DownloadString(SomeUnimportantURL)
    'Do something useful here
    wc.Dispose
    ============= End VB CODE ========================


    The above code takes around 7 seconds then when clicked again and all subsequent times its instant.

    Is the WebClient the best option I could use for this or would something else be better?

    Is there a way to set the Proxy to stop the delay?

    Please help guys....

    Thanks,
    555

  2. #2

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    11

    Re: "WebClient" very slow on initial request

    A BUMP for the pro's...

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: "WebClient" very slow on initial request

    Are you using a Proxy in IE? If not, try setting the .Proxy property to Nothing and see if it runs faster.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,266

    Re: "WebClient" very slow on initial request

    This
    Code:
            Dim wc As New System.Net.WebClient
            Try
                Dim s As String = wc.DownloadString("uriHere") 'without knowing the uri it is hard to diagnose
            Catch ex As Exception
                Stop
            End Try
            'Do something useful here
    may behaving correctly, depending on the uri. It may be DNS.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    11

    Re: "WebClient" very slow on initial request

    Quote Originally Posted by Negative0 View Post
    Are you using a Proxy in IE? If not, try setting the .Proxy property to Nothing and see if it runs faster.
    Negative you got it!
    I could have sworn that I had already tried it. May I tried it in a way that didn't work i donno. But I do know is, the initial request is instant now. This wasn't only for the WebClient... HttpWebRequest also delayed on initial request also. That is, until I applied this fix. GREAT!

    Thanks again...

    555

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width