dagan
New member
- Joined
- Oct 29, 2009
- Messages
- 3
- Programming Experience
- 3-5
Hi All,
I have this little code snippet - that trawls through some site and just like a spider gets the HTTP requests...
This should do for about 100 or so sites - so I have created a progress bar and tied it with a thread so the process can run in the background - and not lag the whole programme (and also I could show progress neatly with the bar) - however when executed (although I get the progress bar coming up nicely) - the program still seems to lag...
What am I doing wrong???
here is the code:
I have this little code snippet - that trawls through some site and just like a spider gets the HTTP requests...
This should do for about 100 or so sites - so I have created a progress bar and tied it with a thread so the process can run in the background - and not lag the whole programme (and also I could show progress neatly with the bar) - however when executed (although I get the progress bar coming up nicely) - the program still seems to lag...
What am I doing wrong???
here is the code:
VB.NET:
Private Sub AllSitesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllSitesToolStripMenuItem.Click
Dim tbladpt As New SiteCheckDataSetTableAdapters.SitesTableAdapter()
Dim tbl As New SiteCheckDataSet.SitesDataTable()
tbl = tbladpt.GetData()
Progress.progressBar.Value = 0
Progress.progressBar.Maximum = tbl.Rows.Count
Progress.Show()
Progress.t = New Thread(AddressOf ScanSites)
Progress.t.Start()
End Sub
Public Sub ScanSites()
Dim tbladpt As New SiteCheckDataSetTableAdapters.SitesTableAdapter()
Dim tbl As New SiteCheckDataSet.SitesDataTable()
Dim d As New SiteScanDelegate(AddressOf SiteScan)
tbl = tbladpt.GetData()
For Each rs As DataRow In tbl
Invoke(d, New String() {rs("domain")})
Next
Invoke(d, New String() {"FinishedJob"})
End Sub
Delegate Sub SiteScanDelegate(ByVal str As String)
Public Sub SiteScan(ByVal url As String)
If url = "FinishedJob" Then
Progress.Hide()
Else
Dim str As String = ""
If InStr(url, "http://") = 0 Then url = "http://" & url
Dim request As HttpWebRequest = WebRequest.Create(url)
Try
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
str = reader.ReadToEnd()
reader.Close()
Catch ex As System.Exception
str = ""
Finally
Progress.progressBar.Value += 1
End Try
End If
End Sub