How to abort a thread while close the form?

  • Thread starter Thread starter yxq
  • Start date Start date
Y

yxq

Hello
There is a thread in my form, when user click the Close button on form, i
want to abort the thread, then close the form, but my code seem not to work.

Private Sub frm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

'I do not know whether the thread is running.

Dim blnThreadRunning As Boolean
Try
Dim a As String = MyThread.ThreadState()
blnThreadRunning = True
Catch
blnThreadRunning = False
End Try

If blnThreadRunning = True Then
Do Until MyThread.ThreadState = ThreadState.Aborted
Try
MyThread.Abort()
Catch
End Try
Loop
End If
End Sub
 
yxq said:
Hello
There is a thread in my form, when user click the Close button on
form, i
want to abort the thread, then close the form, but my code seem not
to work.

Private Sub frm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

'I do not know whether the thread is running.

Dim blnThreadRunning As Boolean
Try
Dim a As String = MyThread.ThreadState()
blnThreadRunning = True
Catch
blnThreadRunning = False
End Try

If blnThreadRunning = True Then
Do Until MyThread.ThreadState = ThreadState.Aborted
Try
MyThread.Abort()
Catch
End Try
Loop
End If
End Sub

Try
mythread.abort
mythread.join
instead.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top