473,388 Members | 1,427 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,388 software developers and data experts.

Multiple Thread Creation and Control

Ok so I'm creating this event scheduler in VB.NET with the use of
threads. We would like the customer to be able to declare however many
threads they want.

For example...

Lets say the user wants to be able to have 10 threads all running at
the same time. Well I would need a way to dynamically created that
number of threads at runtime and be able to control them all. Up until
now I have been statically control the thread count so I have been able
to easily control them.

Observe:

'---Event Classes----------------------------
Public Task1 As New EventClass()
Public Task2 As New EventClass()
Public Task3 As New EventClass()
Public Task4 As New EventClass()
Public Task5 As New EventClass()
Public Task6 As New EventClass()
Public Task7 As New EventClass()
Public Task8 As New EventClass()
Public Task9 As New EventClass()
Public Task10 As New EventClass()
'---End Event Classes------------------------
'---Threads----------------------------------
Public Thread1 As New System.Threading.Thread(AddressOf
Task1.ExecuteShell)
Public Thread2 As New System.Threading.Thread(AddressOf
Task2.ExecuteShell)
Public Thread3 As New System.Threading.Thread(AddressOf
Task3.ExecuteShell)
Public Thread4 As New System.Threading.Thread(AddressOf
Task4.ExecuteShell)
Public Thread5 As New System.Threading.Thread(AddressOf
Task5.ExecuteShell)
Public Thread6 As New System.Threading.Thread(AddressOf
Task6.ExecuteShell)
Public Thread7 As New System.Threading.Thread(AddressOf
Task7.ExecuteShell)
Public Thread8 As New System.Threading.Thread(AddressOf
Task8.ExecuteShell)
Public Thread9 As New System.Threading.Thread(AddressOf
Task9.ExecuteShell)
Public Thread10 As New System.Threading.Thread(AddressOf
Task10.ExecuteShell)
'---End Threads-----------------------------

If (Thread1.IsAlive = False) Then
If (ResetFlag1 = True) Then
Thread1 = Nothing
GC.Collect()
Thread1 = New System.Threading.Thread(AddressOf
Task1.ExecuteShell)
End If
Task1.EventID = "1"
Thread1.Start()
ResetFlag1 = True
ElseIf (Thread2.IsAlive = False) Then
If (ResetFlag2 = True) Then
Thread2 = Nothing
GC.Collect()
Thread2 = New System.Threading.Thread(AddressOf
Task2.ExecuteShell)
End If
Task2.EventID = "2"
Thread2.Start()
ResetFlag2 = True
....
End If

As you can see I have a "queue" of 10 static threads that I see if they
are alive before assigning a job to them. And whenever I want to kill
one I just put in my "EventID", find the one I want and kill it.

I need to be able to create as many threads as I need, and control them
all. Any suggestions???

Mar 28 '06 #1
0 1176

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
5
by: Martin Maat [EBL] | last post by:
Hi, I have a GUI application that responds to events coming from an externaql application. In the implementing code for the event I need to create a GUI control and "parent" the control into the...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
11
by: TrtnJohn | last post by:
I have a class that writes data to the serial port and has a separate thread to read data from the same port. Typically the main thread writes requests to the serial port and then returns to the...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
11
by: Olie | last post by:
This post is realy to get some opinions on the best way of getting fast comunication between multiple applications. I have scowered the web for imformation on this subject and have just found...
3
by: Le Minh | last post by:
I receive this message: "System.InvalidOperationException: Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on" .... this is a exception....
6
by: AliR \(VC++ MVP\) | last post by:
Hi everyone, I have a Socket derived class that parses the received data into a message, populates a object with that information and then tries to send an event to inform the owner of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.