473,769 Members | 5,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Threadin g.Thread(Addres sOf
Task1.ExecuteSh ell)
Public Thread2 As New System.Threadin g.Thread(Addres sOf
Task2.ExecuteSh ell)
Public Thread3 As New System.Threadin g.Thread(Addres sOf
Task3.ExecuteSh ell)
Public Thread4 As New System.Threadin g.Thread(Addres sOf
Task4.ExecuteSh ell)
Public Thread5 As New System.Threadin g.Thread(Addres sOf
Task5.ExecuteSh ell)
Public Thread6 As New System.Threadin g.Thread(Addres sOf
Task6.ExecuteSh ell)
Public Thread7 As New System.Threadin g.Thread(Addres sOf
Task7.ExecuteSh ell)
Public Thread8 As New System.Threadin g.Thread(Addres sOf
Task8.ExecuteSh ell)
Public Thread9 As New System.Threadin g.Thread(Addres sOf
Task9.ExecuteSh ell)
Public Thread10 As New System.Threadin g.Thread(Addres sOf
Task10.ExecuteS hell)
'---End Threads-----------------------------

If (Thread1.IsAliv e = False) Then
If (ResetFlag1 = True) Then
Thread1 = Nothing
GC.Collect()
Thread1 = New System.Threadin g.Thread(Addres sOf
Task1.ExecuteSh ell)
End If
Task1.EventID = "1"
Thread1.Start()
ResetFlag1 = True
ElseIf (Thread2.IsAliv e = False) Then
If (ResetFlag2 = True) Then
Thread2 = Nothing
GC.Collect()
Thread2 = New System.Threadin g.Thread(Addres sOf
Task2.ExecuteSh ell)
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 1199

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

Similar topics

6
3206
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 list within a single object, which is then placed on a stack(This cuts down thread creation and deletions roughly by a factor of 4). I create up to 12 threads, which then process a single object off of the stack. I use a loop with a boolean...
5
2112
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 GUI. Doing this directly fails, it is not allowed to parent a control that was not created on the main GUI thread into the main GUI through another thread (an exception is thrown on "control.Parent = container;"). So I have to create the...
6
4997
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 for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
7
2695
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 a lock pending, for example. I want to be able to stop a thread temporarily, and then optionally resume it or stop it for good.
11
1218
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 caller. The read thread waits for a response while the application continues running. When a response is received, I want to fire an event. But, I don't want the read thread to raise the event because the event could spawn a whole set of new...
3
3695
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 site, performs a search based on POST variables, retrieves the code, parses the information (including a url for a thumbnail image) and displays the results. I am using threads, since the program will appear to freeze while
11
4346
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 conflicting views and far from ideal solutions. My application has to send small amounts of data about 50bytes to multiple client applications. The catch is that this has to happen about 1000 times a second. My first attempt was .net remotting...
3
30555
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. Can fix it?
6
2376
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 socket that there is message to be processed. But this is not working as the socket receiver method seems to be in a different thread then the form that owns the socket. The receive callback gets the data from the socket and process the...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.