Killing a thread from a different sub (need code)
Before any one comments, ive read all the posts in this subject everything give comments but no CODE....
my app's processing is done in a new thread when the user clicks a button
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyThread As New Thread(AddressOf runProg)
MyThread.Name = "Primary Search Thread"
MyThread.Start()
Me.StatusPanel1Status.Text = "Scanning Please Wait!"
End Sub
ok this all works nicely
i then have a sub for when the user closes the application it simple checks if some files exists and if they do to prompt the user wana filter them yes or no if they click no the application quits (but the thread doesnt)
VB Code:
Private Sub MainApp_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim result As MsgBoxResult = MsgBox("There are still files to filter, do you wish to complete this before exiting", MsgBoxStyle.YesNo, "Input")
If result = MsgBoxResult.Yes Then
RunFilter()
Else
'exit the thread here
End If
End Sub
CODE examples would be really nice right now
Re: Killing a thread from a different sub (need code)
VB Code:
Dim MyThread As Thread = New Thread(AddressOf runProg)
'the other function minus the original thread declaration
'goes here
Private Sub MainApp_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim result As MsgBoxResult = MsgBox("There are still ......", MsgBoxStyle.YesNo, "Input")
If result = MsgBoxResult.Yes Then
RunFilter()
Else
MyThread.Abort()
End If
End Sub