473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Multithreading with queue

10
Hi All,

I have more than 5 thread task that is dynamic number.

I want to run 5 thread at a time.
when one of the 5 thread is finished another one queue thread start to run.
Then continue to run until all queue thread is finished.

I have problem of how to queue the thread if over 5 thread.
how to pass the parameter? sPar.Item(iIndx).ToString()

Below is my code.

Expand|Select|Wrap|Line Numbers
  1.  Private Const MAX_THREADS As Integer = 7
  2.     Private threads(MAX_THREADS) As Thread
  3. Private Sub btnRunThread_Click(ByVal sender As System.Object, _
  4. ByVal e As System.EventArgs) Handles btnRunThread.Click
  5.         Dim cThread As New ThreadClass
  6.         Dim rnd As New Random
  7.  
  8.         For i As Integer = 0 To MAX_THREADS
  9.             cThread.sPar.Add(i.ToString())
  10.             If i > 4 Then
  11.                 threads(i) = New Thread(AddressOf cThread.ThreadMethod1)
  12.                 cThread.iIndx = i
  13.                 threads(i).Start()
  14.                 threads(i).Join()
  15.             Else
  16.                 threads(i) = New Thread(AddressOf cThread.ThreadMethod1)
  17.                 cThread.iIndx = i
  18.                 threads(i).Start()
  19.             End If
  20.         Next
  21. End Sub
  22.  
  23. Public Class ThreadClass
  24.     Public sPar As New ArrayList
  25.     Public iIndx As Integer
  26.  
  27.     Public Sub ThreadMethod1()
  28.         Thread.Sleep(200)
  29.         For i As Integer = 1 To 100
  30.             Console.WriteLine("Thread " & sPar.Item(iIndx).ToString() & ": " & i)
  31.         Next
  32.     End Sub
  33. End Class
  34.  
Is there any solution or advice, please guide me.
Aug 23 '10 #1
0 892

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: James R. Saker Jr. | last post by:
I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: | qsize(self) | Return the approximate size of the queue (not reliable!). Any thoughts on why this is unreliable (and...
3
by: kelkel | last post by:
Hi all, I got a question here which about using queue. i have create a class of queue. Public Sub Add(ByVal data As Object) SyncLock Me _Data.Enqueue(data) Monitor.Pulse(Me) End SyncLock End...
3
by: Chris Fink | last post by:
I have written a dll that performs file IO that will be called frequently. I have been running into problems where file locking is occuring when a thread cannot access the file since it is being...
9
by: Jurgen | last post by:
Hello, I've a C# program that: 1) loads data for 30000 items from SQL Server 2) loops through all the items and does some extensive calculaltions on the data 3) loops through all the items to...
0
by: Mike | last post by:
Ok, I think I have an understanding of how to (or not to) implement a thread safe message queue. There are several key elements, I will try to be brief without too much code. * Use the dotnet...
20
by: Charles Law | last post by:
Consider the following scenario: A data packet is sent out of a serial port and a return packet is expected a short time later. The application sending the packet needs to send another packet...
4
by: Manuel | last post by:
I have a long function that needs to be done 1000 times. I'm multithreading it, but I don't want to load them up all at once, instead load them 10 at a time. So far the only way I can get it to...
1
by: Jeffrey Barish | last post by:
Several methods in Queue.Queue have warnings in their doc strings that they are not reliable (e.g., qsize). I note that the code in all these methods is bracketed with lock acquire/release. These...
11
by: OlafMeding | last post by:
Because of multithreading semantics, this is not reliable. This sentence is found in the Python documentation for "7.8.1 Queue Objects". This scares me! Why would Queue.qsize(), Queue.empty(...
6
by: Celldss | last post by:
I'm doing a standard AD query to retrieve a list of workstations that match certain criteria. I would like to iterate through that list and see if the workstations are still on the network and have...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.