Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8141633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:34:32+00:00 2026-06-06T12:34:32+00:00

I have a simple program that checks webpages for strings, example: Private Sub Button1_Click(ByVal

  • 0

I have a simple program that checks webpages for strings, example:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim urls() As String = TextBox1.Lines()
    Dim links() As String = TextBox2.Lines()
    For Each url As String In urls
        CheckForLinks(url, links)
    Next

End Sub
Private Sub CheckForLinks(ByVal url As String, ByVal links() As String)
    Dim wc As New WebClient()
    Dim source As String = wc.DownloadString(url)
    'MessageBox.Show(source)
    For Each link As String In links
        If (source.IndexOf(link) <> -1) Then
            TextBox3.AppendText("url: " + url + " link: " + link + vbCrLf)
            Exit For
        Else
            TextBox3.AppendText("url: " + url + " link: " + "NOT FOUND" + vbCrLf)
        End If
    Next

End Sub

It works fine, but is slow, as it checks one webpage at a time.

I realize i can use a parallel.for each in the button1_click sub, but im worried that it might generate a ton of threads and overload the web connection.

I would prefer to be able to set the exact amount of threads it uses, but im not sure where to start. Eg how would i assign each url to a thread etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:34:34+00:00Added an answer on June 6, 2026 at 12:34 pm

    Well you can certainly use Parallel.ForEach and specify the maximum degree of parallelization using this overload where you can specify a ParallelOptions.

    Note that you shouldn’t do this in your click handler though – your UI will block until it’s all finished. You either want to perform the Parallel.ForEach in a new thread, or start new tasks (using Task.Factory.StartNew) and rely on the parallelism limits within that. (Or create a custom task factory for the purpose. There are docs around that within the TPL documentation, I believe.)

    Likewise your CheckForLinks method mustn’t try to update the UI within a non-UI thread. For WinForms, you can use Control.Invoke to get back to the UI thread – or if you’re using tasks, you could add a continuation (Task.ContinueWith) and specify a task scheduler tied to the UI synchronization context.

    Frankly, doing this in a console app would be significantly simpler – just use Parallel.ForEach and you’ll be fine 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create a simple program that i have a array of strings
I have a really simple program that checks the date and returns if the
I have a simple C# program that checks the database for updates every minute
Say I have simple program that emulates a board game with a number of
I have this simple program that computes salaries for four different worker types. It's
I have a simple program that creates a thread, loops twenty times and then
I have a simple program that reads data from a PNG into a 2D
I have a simple python program that I'd like to daemonize. Since the point
I have a simple forms program that I have been fighting with for a
I have a simple Delphi program that I'm working on, in which I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.