I
Ivan
Hi All,
my question is how to teminate a running thread...
it sounds simple but in fact i 'm having problem with it
firstly, i create a new thread (refer to follow example code) and start it
on form load
once the form button on clicked... i try terminate the thread... but an
exception was catched...
example code as follow..
Public Class CounterIncrement()
Public lngCounter As Long = 0
Pubilc Sub Increment()
Do
lngCounter += 1
Loop Until intCounter > 100000
End Sub
End Class
Public Class TestForm : Inherits System.Windows.Form
Private objThread As Thread()
Private Sub form1_load() handles form1.load
Dim objCounter As New CounterIncrement()
objThread = New Thread(AddressOf objCounter.Increment)
objThread.Start
Do
Application.DoEvents
Loop Until Not objThread.IsAlive
end sub
Private Sub button1_Click() handles button1.click
objThread.Abort <==== this won't terminate the thread... but make it
state as AbortRequested....?? why???
End Sub
End Class
my question is how to teminate a running thread...
it sounds simple but in fact i 'm having problem with it
firstly, i create a new thread (refer to follow example code) and start it
on form load
once the form button on clicked... i try terminate the thread... but an
exception was catched...
example code as follow..
Public Class CounterIncrement()
Public lngCounter As Long = 0
Pubilc Sub Increment()
Do
lngCounter += 1
Loop Until intCounter > 100000
End Sub
End Class
Public Class TestForm : Inherits System.Windows.Form
Private objThread As Thread()
Private Sub form1_load() handles form1.load
Dim objCounter As New CounterIncrement()
objThread = New Thread(AddressOf objCounter.Increment)
objThread.Start
Do
Application.DoEvents
Loop Until Not objThread.IsAlive
end sub
Private Sub button1_Click() handles button1.click
objThread.Abort <==== this won't terminate the thread... but make it
state as AbortRequested....?? why???
End Sub
End Class