How to abort a thread?

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

yxq

Hello,
I want to abort a thread when form closed, but system will hang using the
code below sometimes.

*****************************************************
Private Sub frm1_Closed(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Closed
If ScanThread.ThreadState <> ThreadState.Stopped Then
ScanThread.Abort()
Do Until ScanThread.ThreadState = ThreadState.Stopped
Application.DoEvents()
Loop
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top