简体   繁体   中英

Windows form application not closing properly

I'm running a simple .NET Windows Forms application. When I click the close button, the Windows form gets closed, but the process is not closing. When I look at the Task Manager, I see that the process for the application is still live, as a background process. 在此处输入图片说明

Can somebody explain why that is? Am I missing some function when it's closing?

You need to call

Application.Exit();

in your Form's closing event.

Application.Exit
Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. This is the code to use if you are have called Application.Run (WinForms applications), this method stops all running message loops on all threads and closes all windows of the application.

// WinForms app
System.Windows.Forms.Application.Exit();

Put this code on you from's closing event.

The main reason for not close properly, When your application works with the multi threading. You should use the following, it's works for me as well.

Application.ExitThread();

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