Results 1 to 9 of 9

Thread: better way to exit a program with a thread

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210

    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:
    1. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         If t.IsAlive = True Then
    3.             On Error GoTo Quit
    4.             t.Abort()
    5.             t.Resume()
    6.             t.Abort()
    7.         End If
    8. Quit:
    9.     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
  •  



Click Here to Expand Forum to Full Width