简体   繁体   中英

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?

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!

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.

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.

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(...); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM