Uneable to stop tcp multithreaded server process
-
I have a problem stopping the server process. Everything seems fine when i stop my multithreaded server, no exceptions when i shut down the application. But the server program wont stop executing. I cant find any more threads that i have forgot to abort. Still if i try to abort the CurrentThread in the end of the program i get an AbortException that cant be handled by the application. Is there something else i can try? Michelangelo
-
I have a problem stopping the server process. Everything seems fine when i stop my multithreaded server, no exceptions when i shut down the application. But the server program wont stop executing. I cant find any more threads that i have forgot to abort. Still if i try to abort the CurrentThread in the end of the program i get an AbortException that cant be handled by the application. Is there something else i can try? Michelangelo
Without seeing any code, all I can tell you is that to handle the seemingly uncatchable
ThreadAbortException
, handle the current AppDomain'sAppDomain.UnhandledException
event to catchThreadAbortException
s (or any others you might want caught).Microsoft MVP, Visual C# My Articles
-
I have a problem stopping the server process. Everything seems fine when i stop my multithreaded server, no exceptions when i shut down the application. But the server program wont stop executing. I cant find any more threads that i have forgot to abort. Still if i try to abort the CurrentThread in the end of the program i get an AbortException that cant be handled by the application. Is there something else i can try? Michelangelo
Hi, I presume your server is using a thread which continually listens on a port by running it on a thread. Currently when you close your program down the lightweight process (the thread) continues to be executed. In the applications "closing" event you need to ensure all threads running are interrupted and cleaned up. Dont use the STOP method as it is very bad.. you could end up with part written data for the instance of the program. Theres a pretty complete guide here on threads: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchusingthreads.asp[^] Which is worth a glance, but for the quick solution do this in the closing event for the main form/application:
threadinstance.Interrupt();
-
I have a problem stopping the server process. Everything seems fine when i stop my multithreaded server, no exceptions when i shut down the application. But the server program wont stop executing. I cant find any more threads that i have forgot to abort. Still if i try to abort the CurrentThread in the end of the program i get an AbortException that cant be handled by the application. Is there something else i can try? Michelangelo
The threads you have created may be foreground threads. These threads will keep the process running until they stop. Try setting the
Thread.IsBackground
property to true. Once all foreground threads have stopped executing the runtime will abort all background threads automatically.