Application process not ending when I close the form? (C#)
Experimenting with the TcpClient and TcpListener class and for some reason when I have a couple of threads running and I close the form the process does not end but the form disappears.
I have to manually kill the process with the VS IDE or task manager.
Nothing in the form is still running from what I can tell when I close 开发者_开发问答the program but the process does not end.. I insert breakpoints everywhere and even the console output says the threads exited.
Anyone know what's going on here?
The main thread of your application is waiting for the threads your spawned to finish. You can set the IsBackground
property of your threads to true
so they do not stop your process from terminating:
From MSDN:
A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete.
精彩评论