eran Posted May 17, 2003 Posted May 17, 2003 Do I have to close all the opened sockets when I close the app, or the sockets are being closed automaticly when the app is closed? Quote
*Gurus* Derek Stone Posted May 17, 2003 *Gurus* Posted May 17, 2003 (edited) You should explicitly close them. Edited May 18, 2003 by Derek Stone Quote Posting Guidelines
Madz Posted May 18, 2003 Posted May 18, 2003 The problem i have faced is similar to like this I have a TCP Listner, and i am assigining a new thread to a new incoming connection, if there are some active connections then although application is closed its proces in back is still running and then i have to go to taskmanager and then kill the process Quote The one and only Dr. Madz eee-m@il
*Gurus* Derek Stone Posted May 18, 2003 *Gurus* Posted May 18, 2003 Set the IsBackground property of each of your threads to true. Quote Posting Guidelines
eran Posted May 20, 2003 Author Posted May 20, 2003 In any case, if I have a thread and in this thread I have int ret = soc.Receive(receive, receive.Length, 0); I will have to use the 'Suspend' method before aborting the thread. No? Quote
*Gurus* Derek Stone Posted May 20, 2003 *Gurus* Posted May 20, 2003 No, however you should close that socket prior to aborting the thread, out of courteousness to the other endpoint. Quote Posting Guidelines
eran Posted May 21, 2003 Author Posted May 21, 2003 suspending the task before closing it, resolved me a problem. When I used to close a thread which has the command int ret = soc.Receive(receive, receive.Length, 0); gave the following Exception: System.Threading.ThreadAbortException: Thread was being aborted. at System.ComponentModel.Win32Exception..ctor(Int32 error) at System.Net.Sockets.SocketException..ctor() at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 size, SocketFlags socketFlags) at MaleClient.FrmMain.RecieveData() in c:\documents and settings\erany\my documents\visual studio projects\matchmaker\maleclient\frmmain.cs:line 221 Quote
*Gurus* Derek Stone Posted May 21, 2003 *Gurus* Posted May 21, 2003 That is how threads work-- the only way to terminate them is to throw an exception, catch it at the application level and ignore it. Calling Thread.Suspend() is essentially doing nothing, since a subsequent call to Thread.Abort() will implicitly resume the thread and then abort it. Quote Posting Guidelines
*Gurus* Derek Stone Posted May 21, 2003 *Gurus* Posted May 21, 2003 No, they won't. Dim t As New Thread(AddressOf ThreadProc) t.Start() Thread.Sleep(2000) t.Abort() Private Sub ThreadProc() Try Do Trace.WriteLine("Executing...") Loop Catch e As ThreadAbortException MessageBox.Show("""Thread.Abort()"" has been called.", "") End Try End Sub Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.