Results 1 to 3 of 3

Thread: kill all app threads - RESOLVED

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210

    kill all app threads - RESOLVED

    In vb6 i have this code to kill all my forms on exiting the app:

    VB Code:
    1. For Each frm In Forms
    2.         Unload frm
    3.         Set frm = Nothing
    4.     Next

    It is possible to make something like this to kill my threads in VB.Net?

    Thank you,
    Guilherme Costa
    Last edited by gccosta; May 23rd, 2004 at 08:49 AM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    How about Application.Exit?
    In vb.Net, forms are instances of a class. Thus, they have a scope. They can be declared in a module, form, event, etc, and exist within that scope. It's similar to dimming a variable. When the variable goes out of scope, it's gone.
    That's kind of simplified, but is the basic idea. Form1 doesn't "load" (or unload) an existing Form2. It creates a new instance of Form2.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Location
    Porto Alegre, RS
    Posts
    210
    I´ve done this sub to kill threads:

    VB Code:
    1. Public Sub finalizaThread(ByRef Tarefa As Thread)
    2.         Try
    3.             While Not Tarefa Is Nothing
    4.                 If Tarefa.ThreadState = ThreadState.Suspended Or Tarefa.ThreadState = ThreadState.SuspendRequested Then
    5.                     Tarefa.Resume()
    6.                     Tarefa.Sleep(100)
    7.                     Tarefa.Abort()
    8.                 Else
    9.                     Tarefa.Abort()
    10.                 End If
    11.                 Tarefa.Sleep(100)
    12.                 Tarefa = Nothing
    13.             End While
    14.         Catch ex As Exception
    15.             gravaErro(ex)
    16.         End Try
    17.     End Sub

    This sub solves my doubt!!

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