Hi All
Does Application.Exit(); kill of a program cleanly. I ask as this is what I have done up to now and up unitl now it has worked, the program I am currently writing is bigger a slightly more complex (7 serial ports, 2 Dll's etc). When the program is ended via Application.Exit(); it dissapears from the Applications tab, but is still in the processes tab. If you select it and End Process it comes back each time! So barring a wooden stake is there any way of killing cleanly?
Glenn

3 answers
AFAIK Application.Exit() will force the Main (UI) thread to return. Any other threads running in the app should be handled otherwise. Only when these return will the .exe stop.
answered one year ago by:
2499
329
So, if I ignor it it will go away? Glenn
2499
Well I suppose you could look at it like that :-P I would recommend manually ending (killing, if necessary) your other threads before calling Application.Exit() though
In addition to what foamy said, the other way of exiting the program that i usually use is the End Process itself by
Beside this, concerning the application restart, it seems that there is another process that is initiating this process in a kind of loop, so whenever this process ends its starts again so you should search for the process that is causing this restart or maybe check if its a windows service.
answered one year ago by:
1556
329
Thanks, I will give that ago! Glenn
2499
I love methods named Kill, Freeze, Damage and the likes ;)
329
My only regret is some still has to implement a Destroy method that does something useful!
17279
You can also kill the application stone dead with Environment.Exit(-1). Not recommended, except as a last resort, for WF apps though :)
If you're creating your own threads, then set their IsBackground property to true before you run them.
When the UI thread ends, all background threads which are still running will be terminated automatically allowing the process itself to end.
If you don't so this, then the threads will be 'foreground' by default and so the process won't end until all foreground threads have ended.
However, I agree with foamy that it's best to terminate your threads manually if you can in case there's any clean up to be done.
answered one year ago by:
17279
329
Cheers again Vulpes, matter of interest you must monitor this board all the time, as you have come back at weekends, unsocial times of the day. (like early morning!) Glenn
2499
Well you'd have to consider which timezone vulpes is in (I have no idea, actually :-P) Good point on the background property, didn't know that :)
329
Yeah, but even so he has to sleep some time I hope. I have had answers from him at mid day GMT & midnight GMT Glenn
17279
When I'm at home, my laptop's on all day so you could see me posting anytime within a 16 hour window, depending on what else I'm doing. However, the board doesn't take much monitoring these days, with only a handful of questions asked and people to answer them.
2499
Still, it's comforting to know there's a vulpes watching the board :D
17279
Like sciurus, we're an alert genus ;)