views:

857

answers:

3

Hey guys,

When I launch my application, and press the "X" button on my app, or my quit button which deploys: me.close It will not fully close the application. Like the instance is still running in Visual Studio or if you go to task manager processes you can still see it there. How would I get this to fully close?

Thanks

Kevin

+3  A: 

One possibility is that you have some threads apart from the main thread running, and those aren't background threads. In general, try debugging it: attach to it from VS, and use Pause button to break it, and look at what threads are there, and what they are doing.

Pavel Minaev
I mean is there a quick and easy way to fix this, by ending the whole process instead of going through all that digging?
Kevin
The only way to fix it is to find out what's wrong. If you have some thread still running, then terminating the process disregarding this thread can lead to data loss (e.g. what if it was writing to a file at that point) and other nasty side effects. That said, if what you want is a _hack_ rather than fix, then `Environment.Exit()` on main thread will shut down all running threads and then the process.
Pavel Minaev
+1  A: 

If you do have thread(s) running within the app, set IsBackground property as True.

Thread.IsBackground Property on MSDN

Remarks

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.

o.k.w
+1  A: 

The "End" keyword is what you're looking for.

Put it in the FormClosed event.

tbs