Results 1 to 9 of 9

Thread: How can i do that without using timer and much faster add google results into listbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Smile 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

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: How can i do that without using timer and much faster add google results into lis

    How is that using a timer?
    My usual boring signature: Nothing

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    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.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    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.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    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:
    1. Imports System.Net
    2.  
    3. Public Class MainForm
    4.  
    5.     Private ReadOnly temp As String = "http://download.piriform.com/ccsetup327.exe"
    6.  
    7.     Private m_dictionary As New Dictionary(Of WebClient, ListViewItem)
    8.  
    9.  
    10.     Private Sub Download(ByVal Path As String, ByVal FileName As String)
    11.         Dim client As New WebClient
    12.         AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressChanged
    13.         AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCompleted
    14.  
    15.         Dim lvw As New ListViewItem With {.Text = FileName}
    16.         lvw.SubItems.Add("0%")
    17.         Me.FileDownLoadListView.Items.Add(lvw)
    18.  
    19.         client.DownloadFileAsync(New Uri(temp), Path & Filename)
    20.         Me.m_dictionary.Add(client, lvw)
    21.     End Sub
    22.  
    23.     Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
    24.         m_dictionary.Item(CType(sender, WebClient)).SubItems(1).Text = e.ProgressPercentage & "%"
    25.     End Sub
    26.  
    27.     Private Sub DownloadFileCompleted(ByVal sender As Object, _
    28.                                                        ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
    29.         Dim client As WebClient = DirectCast(sender, WebClient)
    30.         client.Dispose()
    31.         m_dictionary.Remove(client)
    32.         Debug.WriteLine(m_dictionary.Count)
    33.     End Sub
    34.  
    35.     Private Sub StartButton_Click(ByVal sender As System.Object,
    36.                                   ByVal e As System.EventArgs) Handles StartButton.Click
    37.         For i As Integer = 0 To 5
    38.             Download("C:\Temp\", String.Format("FileName{0}.exe", i))
    39.         Next
    40.     End Sub
    41. 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.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: How can i do that without using timer and much faster add google results into lis

    Never mind i have found the answer

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Re: How can i do that without using timer and much faster add google results into lis

    I found out myself

Tags for this Thread

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