|
-
Apr 30th, 2004, 08:02 AM
#1
Thread Starter
Fanatic Member
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
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Apr 30th, 2004, 08:19 AM
#2
How about declaring the Thread object OUTSIDE the subs (ie in the declarations section)?
Then you can access it from anywhere.
I don't live here any more.
-
Apr 30th, 2004, 08:24 AM
#3
Thread Starter
Fanatic Member
HOW ??? Sorry this is first things ive done with threading
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Apr 30th, 2004, 08:25 AM
#4
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
I don't live here any more.
-
Apr 30th, 2004, 08:43 AM
#5
Thread Starter
Fanatic Member
Yeah done that but the application still seems to be running in my task manager. if it the case that the thread will wait until its run or will it quit stright away ????
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Apr 30th, 2004, 08:55 AM
#6
Thread Starter
Fanatic Member
Ive checked the state of the thread and it keeps coming back as unstarted ???any ideas ?
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Apr 30th, 2004, 05:54 PM
#7
Hi.
If the thread is running a loop, then abort won't close it down. At least, that's my experience.
What I usually do, is use a public boolean.
Then in I would make the loop like this:
VB Code:
While Not MyAbort
'do things here
End While
Then, to stop the thread I would just set the MyAbort=True.
The loop will exit, and the thread will terminate.
This usually works for me.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|