Skip to content

Kill Threads

oc A

Asked Mar 4, 2008, 12:03 AM EST1 answer
Share
LinkedInX

I am using VB.NET 2003 windows appln.... In this appplicatn i am creating many threads on a button click.... The code is

    Private Sub Initstart()
        Label5.ForeColor = System.Drawing.Color.Green
        Label5.Text = "Service Running"
        If Listening = False Then
            Dim T As New Thread(AddressOf Listen)
            T.IsBackground = True
            T.Start()
        Else
            Listening = False
        End If
    End Sub

    Private Sub Listen()
        Listening = True
        Listener.Start()
        Do Until Listening = False
            sb.Socket = Listener.AcceptSocket()
            sb.Socket.BeginReceive(sb.Buffer, 0, sb.Buffer.Length,      SocketFlags.None, AddressOf ReceiveCallBack, sb)
        Loop
    End Sub

    Private Sub ReceiveCallBack(ByVal ar As IAsyncResult)
    End Sub


In another Button click i want to kill all these threads and again go to Listening mod e... How i can do the coding for this
Anybody plz help

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Threads kill themselves generally, when they finish executing, just as a
    function is removed from the stack when it is finished executing. You can
    call the Abort() method on the thread if necessary. Note that this will
    raise a ThreadAbortException, which you will have to handle.
    0