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???