-
Nov 17th, 2014, 07:52 AM
#1
Thread Starter
Member
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> mph</span>", 0))
UL(TextBox4, GetBetween(TextBox3.Text, "<span class=""nowrap""><b>", "</b> 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.
-
Nov 17th, 2014, 09:16 AM
#2
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.
-
Nov 17th, 2014, 10:32 AM
#3
Thread Starter
Member
Re: Operation timed out (but why?)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|