Hi! I have a slight problem with multithreading.

There is many threads active in the application
and they are all kept in an arraylist.

so when I try to quit the program, it loops through the arraylist and exits all the threads....

but something else is making the program "unwilling" to shut down, leaving it invisible, still running...

So I was wondering if there is a way to get ALL active (stillAlive) threads in the application and terminate them?

Re: Improper shutdown 80 80

Terminate the thread once it finishes its work, don't wait to loop on the threads and Kill them...

Re: Improper shutdown 80 80

That's not really what I want to do, It's for a chat program with each client having it's own thread to work on, so when the server is to shut down the loop sends a message to each connected client that it is shutting down, after that the thread is aborted.

So I don't really know why it won't shut down since the close sub checks if they are still alive and if so it terminates the thread :(

Re: Improper shutdown 80 80

Give me your code "that loops for threads and kills them"

Re: Improper shutdown 80 80

The clienthandler is a class I created which contains the clients Name, Thread & socket (tcpclient)

Sub ShutDown()
'here is the loop for the clients threads
            For n As Integer = 0 To ClientArray.Count - 1
                Dim ch As clienthandler = CType(ClientArray(n), clienthandler)
                Broadcast(ch, "QUIT|")
            DoListen = False
'and this is for a listen loop that checks for incoming connections
            If ListenThread IsNot Nothing AndAlso ListenThread.IsAlive Then
            End If
        Catch ex As Exception
            MsgBox("(166): " & ex.Message & vbCrLf & vbCrLf & ">> Om du inte kan tyda detta felmeddelande kontakta Datanizze <<")
        End Try
    End Sub
Re: Improper shutdown 80 80

thank you for the link! It worked (environment.exit)

However, at first I put the code in the wrong places making it quit a liiiittle too soon :D all fixed now (I think) :P ... but you know programming, solving one problem -> 10 new problems appears MAGICALLY :)

Thou shall receive a reputation-link-click from me now :twisted:

Re: Improper shutdown 80 80

You're welcome :) I'm happy you solved it but I don't understand your note!!

Re: Improper shutdown 80 80

I don't understand your note!!

hehe.. I added your answer to your reputation by clicking
"Add to RamyMahrous's Reputation" as a thank you for helping me.

Re: Improper shutdown 80 80

(oops dual posts)

Re: Improper shutdown 80 80

loool you didn't :)

Re: Improper shutdown 80 80

ooo yes I did.. but it might not have worked ;) I'll try again then :cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.