Md Kamruzzaman Sarker
Md Kamruzzaman Sarker

Reputation: 2407

Application doesn't terminate

My problem is that the application doesn't terminate when I close the form using the close box on the caption bar.

When I am in the middle of some I/O operation i want to quit the application without performing the I/O operation.

Actually it seems as if the program is closed but task manager's process list shows that it is not.

How i can cancel I/O operation by force?

Upvotes: 0

Views: 179

Answers (4)

chasques
chasques

Reputation: 140

I recommend you the following:

  1. Change the I/O operations to asynchronous mode (using BeginXXX, EndXXX), it will be easier to stop them!
  2. Use a synchronizing event to stop all threads.
  3. Keep track of all threads and call the Kill method.

The first point used along with one of the others (2 or 3) should be enough. good luck!

Upvotes: 2

coder
coder

Reputation: 13248

If you have any infinite loop running in your app make your thread run in background threads before you start them then they will be closed automatically when the application exits.

Try to do it this way:

Thread somethread = new Thread(...);
someThread.IsBackground = true;
someThread.Start(...); 

Upvotes: 1

Randy Minder
Randy Minder

Reputation: 48522

How are you attempting to close your application?

Application.Exit just asks to be closed down via a message loop. It might not happen.

The best way is to close any non-background threads you might have executing. Not doing so will keep your process running.

You can also try Environment.Exit or Environment.FailFast. This is like killing your process.

Upvotes: 1

David.Chu.ca
David.Chu.ca

Reputation: 38684

Closing form only makes the form invisible. However if there is any process running in the main or other thread, the app would not terminated. You have to make sure all the resources are closed or disposed.

Upvotes: 1

Related Questions