Thread termination
-
How do I terminate all the threads my program has started when it closes? I've tryed this code:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (serverThread != null) serverThread.Abort(); if (clientThread != null) clientThread.Abort(); if (receiveRoutineThread != null) receiveRoutineThread.Abort(); }
However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this? -
How do I terminate all the threads my program has started when it closes? I've tryed this code:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (serverThread != null) serverThread.Abort(); if (clientThread != null) clientThread.Abort(); if (receiveRoutineThread != null) receiveRoutineThread.Abort(); }
However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this?Just set the IsBackground[^] property on each thread you create to
true
and you should be done. When the GUI thread shuts down, .NET forces those threads to abort. Regards Senthil _____________________________ My Blog | My Articles | My Flickr | WinMacro -
How do I terminate all the threads my program has started when it closes? I've tryed this code:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (serverThread != null) serverThread.Abort(); if (clientThread != null) clientThread.Abort(); if (receiveRoutineThread != null) receiveRoutineThread.Abort(); }
However, the form closes and a process with my application's name remains running. Can anyone suggest me other way of doing this?Thread.Abort() actually aborts the thread when that operation can be performed. For example, if the thread calls a time-consuming method, the thread won't be aborted until that method returns. _____________________________________________ Tozzi is right: Gaia is getting rid of us. My Blog [ITA] - Developing ScrewTurn Wiki 1.0 Beta3