So I have 2 threads in my application which work fine except for the fact that they will continue taking up rather large amounts of my processor even after they are closed or aborted. This is how one of the loops look like along with some of the main declarations.
Dim Thread1 As System.Threading.Thread
Dim ThreadRunning As Boolean
Dim Thread1Running As Boolean = False
Sub Something()
While True
If ThreadRunning = True Then
Try
...Actions which don't necessarily affect the thread
Catch ex As Exception
End Try
ElseIf ThreadRunning = False Then
If Thread1Running = True Then
Thread1Running = False
Thread1.Abort()
Else
End If
End If
End While
End Sub
Here is the code I used to start the thread.
Thread1Running = True
Dim Thread1 As New System.Threading.Thread(AddressOf Something)
Thread1.IsBackground = True
Thread1.Priority = ThreadPriority.Lowest
Thread1.Start()
Here is the code I use to stop the thread.
ThreadRunning = False
The actions in the thread need threads since timers were too slow for the task(even at a 1 ms interval). The actions are performed fine except for when I abort the thread. In this case the thread will close and the CPU usage will go from around 25% to 0% for this program but then it will crash with a CLR error. When I aborted the thread from outside the sub it would still leave the program CPU usage at 25% which is what I'm trying to avoid. So my main question is: Is it possible to close the thread and reopen it later without it crashing, and so that while it is closed it won't use up 25% of the CPU(or some other rather high CPU performance)? If this isn't enough information I will provide more but I thing this will suffice... hopefully. Thanks for any help.