Inside my thread is Do Loop that search the internet and show's me the results on a list box array.
I need to pause this function, and when i resume it to search from where it was, i tried many ways and one of them is Monitor Pulse.
Expand|Select|Wrap|Line Numbers
- Private _pause As Boolean = False
- Private _threadLock As New Object()
- Private Sub PauseThread()
- _pause = True
- End Sub
- Private Sub ResumeThread()
- _pause = False
- SyncLock _threadLock
- Monitor.Pulse(_threadLock)
- End SyncLock
- End Sub
- Private Sub method(ByVal instr As String)
- Do
- While True
- If _pause = True Then
- SyncLock _threadLock
- Monitor.Wait(_threadLock)
- End SyncLock
- ElseIf _pause = False Then
- 'Do work
- End If
- End While
- Loop
- End Sub
I also tried to Do Loop the "work" bu then i cannot suspend because this means the search or loop it needs to be completed for being "suspended", but the same thing apply here, if i "suspend" and "resume" it it starts from the begginging Monitor.pulse will restarts the thread, it doesn't allow to resume the thread from where it suspend.
I want to know another way that may work for my issue, please help me, Regards Yuri.