Results 1 to 3 of 3

Thread: Operation timed out (but why?)

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2012
    Posts
    41

    Operation timed out (but why?)

    I am using a wunderground.com feed to grab weather to display in my app. The data source is valid, and I have the timer ticking every 300 seconds as to not overload the connection, but it's causing my app to run slow and sometimes become unresponsive, which throws an exception for operation timed out.
    Here is my routine which is causing problems. If I try to hit that URL in my browser, it loads in about 2 seconds and I can keep hammering it repeatedly without becoming slow. Is there a better method to grab the data I want?

    I appreciate any insight.


    Code:
     
    Imports System.Runtime.InteropServices
    Imports System.Threading
    Imports System.Net, System.Text.RegularExpressions
    
    Public Class Form1
        Private Function GetBetween(ByVal Input As String, ByVal STR1 As String, ByVal STR2 As String, ByVal Index As Integer) As String
            Return Regex.Split(Regex.Split(Input, STR1)(Index + 1), STR2)(0)
        End Function
    
        Dim HookL As New UpdateLabel(AddressOf UL)
        Delegate Sub UpdateLabel(ByVal Label As TextBox, ByVal Text As String)
    
        Sub UL(ByVal Label As TextBox, ByVal Text As String)
            If Me.InvokeRequired Then
                Invoke(New UpdateLabel(AddressOf UL), Label, Text)
            Else
                Label.Text = Text
            End If
        End Sub
    
        Sub GetWeather() 'Handles weatherUpdateTimer.Tick
            Try
                Dim Source As String = New WebClient().DownloadString("http://m.wund.com/cgi-bin/findweather/getForecast?brand=mobile&query=19608")
    
                UL(TextBox1, GetBetween(Source, "<span class=""nowrap""><b>", "</b>", 0))
                UL(TextBox2, GetBetween(Source, "<td><b>", "%</b></td></tr>", 0))
                UL(TextBox3, GetBetween(Source, "<tr><td>Wind</td>", "</b>&nbsp;mph</span>", 0))
                UL(TextBox4, GetBetween(TextBox3.Text, "<span class=""nowrap""><b>", "</b>&nbsp;mph</span>", 0))
                UL(TextBox5, GetBetween(Source, "High of ", "F.", 0))
                UL(TextBox6, GetBetween(Source, "Low of ", "F.", 0))
    
                'Dim Radar As String = GetBetween(Source, "<br /><a href=""", """>Zoom into", 1)
            Catch ex As Exception
                System.Console.WriteLine("Weather Exception: " + ex.Message)
                MsgBox("Weather Exception: " + ex.Message)
            End Try
    
        End Sub
    End Class
    Last edited by phuz; Nov 17th, 2014 at 08:25 AM.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: Operation timed out (but why?)

    High level consider WebClient.DownloadFileAsync in tangent with a BackGroundWorker or via Async/Await, a few simple starter examples.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2012
    Posts
    41

    Re: Operation timed out (but why?)

    Thank you!

Posting Permissions

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



Click Here to Expand Forum to Full Width