Correct way to exit an Winform application?

S

sune42

What is the "Correct" way to exit an Winform application?

I have used

Application.Exit();

But I find that the application is still running in TaskManager after
closing it,
so I asume that I am doing something wrong here..

Any ideas?
 
S

Stoitcho Goutsev \(100\)

Windows processes are removed from memory when there is no more runing
threads in them. If you have worker threads make sure that they have
finished before closing the application. Alternatively when you start a
thread you can set IsBackground property to *true* so the the threads will
be killed upon exiting the application; otherwise they will keep working,
thus locking the process in the memory.

The normal way of exiting an application is to stop all worker threads as
well as all UI threads. The UI threads are stopped when the main form's
Close method is called (this ends to message loop). I personally never liked
this Application.Exit. It looked to me too brutal. However I see that in
..NET 2.0 they made it more polite :), so now it looks OK to be used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top