|
-
Mar 4th, 2004, 05:37 PM
#1
Thread Starter
Addicted Member
better way to exit a program with a thread
hi. i just migrated to vb.net yesterday, and i have a bit of trouble exiting a program with a thread.
the program estimates the euler's number in a thread. i can at any time suspend the thread and resume. there's no problem when i make the thread abort when the user clicks stop, but it seems to take longer than just suspending the thread. but there's a problem with suspending a thread. i don't know how to exit the program properly
well, i have a solution but it doesn't seem like a proper way to exit the program. on closing of the form, i have
VB Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If t.IsAlive = True Then
On Error GoTo Quit
t.Abort()
t.Resume()
t.Abort()
End If
Quit:
End Sub
it works perfectly, even when the thread was not even triggered, when the thread is running, and when the thread is suspended. but if i just have the thread abort on exit, when the thread was suspended, it would give me an error. so i had it resume, then abort.
is there a better way to doing this?
thanks.
EDIT:
no wait it doesn't work perfectly
it doesn't close properly when the thread was suspended.
Last edited by nahya^^; Mar 4th, 2004 at 05:45 PM.
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
|