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
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