-
Notifications
You must be signed in to change notification settings - Fork 37
/
ThreadingArray.vb
45 lines (36 loc) · 1.2 KB
/
ThreadingArray.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Imports System.Threading
Public Class ThreadingArray
' Keeps an array of threads if we need to abort update
Private ThreadsArray As List(Of Thread)
Public Sub New()
ThreadsArray = New List(Of Thread)
End Sub
' Adds a thread to the array
Public Sub AddThread(T As Thread)
ThreadsArray.Add(T)
End Sub
' Kills all the threads in the class
Public Sub StopAllThreads()
' Kill all the threads
For i = 0 To ThreadsArray.Count - 1
If ThreadsArray(i).IsAlive Then
ThreadsArray(i).Abort()
End If
Next
End Sub
' Returns true if all threads are complete, else false
Public Function Complete() As Boolean
For Each T In ThreadsArray
If T.ThreadState = ThreadState.Running Or T.ThreadState = ThreadState.WaitSleepJoin Then
' Check if the call to stop threads is flagged
If CancelThreading Then
Return True
End If
' Still working on at least 1 thread, so exit
Return False
End If
Next
' Must all be complete
Return True
End Function
End Class