调用Application.Exit()后,应用程序仍在内存中运行 [英] Application is still running in memory after Application.Exit() is called

查看:198
本文介绍了调用Application.Exit()后,应用程序仍在内存中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Application.Exit()关闭我正在构建的应用程序后,它仍在内存中运行(在任务管理器中检查).因此,当我如上所述关闭它之后再次运行它时,出现此错误一次仅一个实例".您能告诉我如何完全关闭我的应用程序吗?

The application I am building is still running in memory (checked in Task Manager) after it is closed using Application.Exit(). Because of this when I am running it again after closing it as mentioned above, I am getting this error "Only one instance at a time". Can you please tell me how to completely close my application?

推荐答案

似乎这是Windows ap,并且您正在调用System.Windows.Forms.Application.Exit(),但仍有一个线程在后台运行.你尝试过

It seems that this is a Windows ap and you are calling System.Windows.Forms.Application.Exit() but there is a thread still running in the background. Have you tried

Application.ExitThread();

Environment.Exit();

如Jonesy所述,您可以杀死该进程,如果该进程是与当前正在运行的进程不同的应用程序,则传入该进程的进程ID.

You could kill the process as Jonesy mentioned, passing in the process ID of the process if it is a separate application than the current running process.

为此,您需要使用System.Diagnostics.Process命名空间并遍历当前正在运行的进程以获取正确的pid,然后对该pid调用kill.

For that, you need to use the System.Diagnostics.Process namespace and loop through the currently running processes to get the right pid and then call kill on that pid.

这篇关于调用Application.Exit()后,应用程序仍在内存中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆