How can i do that without using timer and much faster add google results into listbox
Hi,i need some help using listbox and pull out urls from google search results and put into listbox faster with no timer if it's possible to do that
without waiting timer to finish.
Here are some examples what i want to change.
This is using with timer.
Using timer it is becoming very slow and need to wait while timer to finish and it is very silly.
I have crossed out all over google pages results but i haven't find the answer to that question until.
This is what i need just to change something in my code but i do not know exactly how i can do that without using timer.
I know that it is possible to do but the question is how ?
Code:
dim i as integer = 0
i = i + 10
Dim wc As New WebClient
Dim source As String = wc.DownloadString("http://www.google.com/search?q=" & TextBox1.Text & "&start=" & i)
Dim m1 As MatchCollection = Regex.Matches(source, "", RegexOptions.Singleline + RegexOptions.IgnoreCase)
For Each m As Match In m1
Dim value As String = m.Groups(0).Value
If Not m.Value.Contains(".png") And Not m.Value.Contains(".gif") And Not m.Value.Contains(".jpg") And Not m.Value.Contains("google") Or
m.Value.Contains("free") Or m.Value.Contains("freeware") Then
ListBox1.Items.Add(m.Groups(0).ToString())
End If
Next
Re: How can i do that without using timer and much faster add google results into lis
How is that using a timer?
Re: How can i do that without using timer and much faster add google results into lis
Why would you use a timer any way? The only scenario i can imagine is you dont no about raising events to notify the download has completed. Loop the method using Async method of webclient thats on a threaded pool and let VB handle the rest.
Re: How can i do that without using timer and much faster add google results into lis
Of course I do not know how to use the raising events or how you say there.
Why do I use the timer ?
I use a timer just because I do not know how else to change and make it work faster without using timer.
I need to adapt this code if it is possible.Need a bit of examples.
Re: How can i do that without using timer and much faster add google results into lis
I dont have time to edit it. Here is an example i wrote that you should easily be able to adapt to your needs.
vb Code:
Imports System.Net
Public Class MainForm
Private ReadOnly temp As String = "http://download.piriform.com/ccsetup327.exe"
Private m_dictionary As New Dictionary(Of WebClient, ListViewItem)
Private Sub Download(ByVal Path As String, ByVal FileName As String)
Dim client As New WebClient
AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCompleted
Dim lvw As New ListViewItem With {.Text = FileName}
lvw.SubItems.Add("0%")
Me.FileDownLoadListView.Items.Add(lvw)
client.DownloadFileAsync(New Uri(temp), Path & Filename)
Me.m_dictionary.Add(client, lvw)
End Sub
Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
m_dictionary.Item(CType(sender, WebClient)).SubItems(1).Text = e.ProgressPercentage & "%"
End Sub
Private Sub DownloadFileCompleted(ByVal sender As Object, _
ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Dim client As WebClient = DirectCast(sender, WebClient)
client.Dispose()
m_dictionary.Remove(client)
Debug.WriteLine(m_dictionary.Count)
End Sub
Private Sub StartButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles StartButton.Click
For i As Integer = 0 To 5
Download("C:\Temp\", String.Format("FileName{0}.exe", i))
Next
End Sub
End Class
Just take not the for loop. Handling of the completed event. You may choose to ignore the progress changed event. Always consult MSDN first when issues arise.
Re: How can i do that without using timer and much faster add google results into lis
What ident showed does seem like a better way to go, but I'm still struck by the fact that you insist that you are using a timer, yet didn't show any code that uses a timer.
Re: How can i do that without using timer and much faster add google results into lis
I need normal example not like this i do not see point using it cuz i do not see good code here.
This is not code what i need.
according to your samples do not meet code, which just offers.
This is more similar to the downloader.
I need more samples
Re: How can i do that without using timer and much faster add google results into lis
Never mind i have found the answer ;)
Re: How can i do that without using timer and much faster add google results into lis