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 8729817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:53:56+00:00 2026-06-13T08:53:56+00:00

I have inherited some code below that works fine, the only problem is, I

  • 0

I have inherited some code below that works fine, the only problem is, I want to be able to limit the number of threads that run at any one time, at the moment I have around 8-10 jobs that run in parallel, I want to limit the number of threads to maybe 3 or 4 at any time, is this possible with the code below without too many changes?

Public Sub threading_Example()

 Dim threadList As New List(Of Thread)

 For n = 0 To numJobs 'about 8-10 normally

     Dim new_job As New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf do_Job))
     Dim job As New Job

     'job.stuff = stuff

     newJob.Start(job)
     threadList.Add(new_job)

 Next

 For Each t As Thread In threadList
     t.Join()
 Next

End Sub

Public Sub do_Job(ByVal job As Object)
   'do task 
End Sub
  • 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-13T08:53:57+00:00Added an answer on June 13, 2026 at 8:53 am

    Try to use Semaphore for example:

    ReadOnly Sem As New Semaphore(3, 4)
    
        Sub Main()
    
            Dim threadList As New List(Of Thread)
            Dim numJobs As Integer
            For n = 0 To numJobs
    
                Dim new_job As New System.Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf do_Job))
    
                new_job.Start()
                threadList.Add(new_job)
    
            Next
    
            For Each t As Thread In threadList
                t.Join()
            Next
    
    
        End Sub
    
    
        Public Sub do_Job(ByVal job As Object)
    
            Sem.WaitOne()
            'only 3 or 4 threads at time can do task
            Sem.Release()
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that I have inherited that generates a matrix of significance
I have inherited some code: Process p = new ProcessBuilder(/bin/chmod, 777, path).start(); p.waitFor(); Basically,
I have inherited some code (from zip file) from a developer and git initialzed,
I have inherited some HTML code and have been asked to align the two
I have the following code in specman that I inherited: some_method() is { var
I have a bit of f# code (below) that takes a unit->obj and evaluates
I'm cleaning up some code, and I have a class with an entity that
Edit: Just found out this is a chrome problem, the code works fine in
So, I inherited some code (below) from someone else and I'm trying to understand
I have inherited some Silverlight\WCF code and now need to implement some new features.

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.