简体   繁体   English

C#Windows应用程序未关闭

[英]C# windows application not closing

I have a C# windows application. 我有一个C#Windows应用程序。 I placed it on a test server, whose set up is not controlled by my company and neither is the seurity context. 我将其放置在测试服务器上,该服务器的设置不受我公司的控制,并且安全性上下文也不受影响。 I double click the exe. 我双击该exe。 App runs and i see my form. 应用程序运行,我看到了我的表格。 I close the application, i open task manager and i still see a foot print of the applicatiion. 我关闭了应用程序,打开了任务管理器,但仍然看到应用程序的外观。

taskkill does not seem to remove it and it is still running in task manager. taskkill似乎没有将其删除,并且仍在任务管理器中运行。

how do i check if any resource is still being held? 我如何检查是否仍保留任何资源?

The likely cause is that a background thread is still running after your application is closed. 可能的原因是在关闭应用程序后,后台线程仍在运行。 Depending on your framework and application configuration a background thread can cause a process to keep running even after the main window is closed. 根据您的框架和应用程序配置,即使关闭主窗口,后台线程也可能导致进程继续运行。

Do you have any threads in your process? 您的进程中是否有任何线程? If so make sure to close them out when the main application window is closing. 如果是这样,请确保在关闭主应用程序窗口时将其关闭。 A good place to do this is in the OnClosing method of a Windows Form 在Windows窗体的OnClosing方法中可以执行此操作

Abusing Application.DoEvents() is another way to get into this kind of trouble. 滥用Application.DoEvents()是解决此类问题的另一种方法。 If you cannot kill the .exe from TaskMgr, your app is stuck waiting for a driver to finish an I/O request. 如果无法从TaskMgr中杀死.exe,则您的应用程序处于等待驱动程序完成I / O请求的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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