应用程序关闭后未完全退出 [英] Application is not exiting completely after closing it

查看:209
本文介绍了应用程序关闭后未完全退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个用于启动应用程序的登录屏幕.

现在,当我输入用户名和密码并单击登录"按钮时,我将隐藏登录"页面并显示主菜单"表单(这是一个Mdi表单,所有表单都在同一Mdi表单上打开).

现在,当我关闭主菜单窗体时,整个应用程序都将关闭,但该应用程序无法完全退出.进程正在持续运行.

如何停止该应用程序?

我认为这是因为我要隐藏(而不是关闭)登录页面.

I have designed a log-in screen for getting the application started.

Now when I enter the user name and password and Click on the Log in Button, I hide the Log in page and display the Main Menu form (Which is an Mdi Form and all forms open on same Mdi form).

Now when I am closing the main menu form, the whole application is getting closed but the application does not exit completely. A process is continually running.

what do I do to stop the application?

I think this is happening because I am hiding (not Closing) the log in page.

推荐答案

是的,没错.重新设计您的应用程序,使您的主窗体成为您的主窗体,或者调用Application.PostQuitMessage或类似的内容,而不是关闭您的窗体并期望您的应用程序自行关闭.我忘记了确切的调用,我在Mac上(对Google毫无帮助),但是我确定它在Application对象上.
Yes, that''s right. Redesign your app so your main form IS your main form, or call Application.PostQuitMessage, or something along those lines, instead of closing your form and expecting your app to close itself. I forget the exact call, and I am on my Mac ( and google is no help ), but it''s on the Application object, I am sure.


在FormClosed下调用此函数Mdi家长表格活动,
将process(.exe)的名称作为参数传递.

使用System.Diagnostics;
公共无效的FindAndKillProcess(字符串名称)
{

foreach(Process.GetProcesses()中的Process clsProcess)
{

如果(clsProcess.ProcessName.StartsWith(name))
{
clsProcess.Kill();

}
}

}
Call this function under FormClosed Event of Mdi Parent Form,and
pass the name of process(.exe) as a parameter.

using System.Diagnostics;
public void FindAndKillProcess(string name)
{

foreach (Process clsProcess in Process.GetProcesses())
{

if (clsProcess.ProcessName.StartsWith(name))
{
clsProcess.Kill();

}
}

}


与其隐藏登录表单,不如执行本技巧/窍门所示的操作:

C#Apps中的多个后续主表单 [ ^ ]

但是,根本问题是,您可能已使线程保持运行状态,或者退出应用程序时未清除某些其他内容.我会找出问题的真正原因,而不是尝试使用创可贴和解决方法.

您唯一的朋友是Visual Studio中内置的调试器.
Instead of hiding the login form do something similar to what is illustrated in this tip/trick:

Multiple Subsequent Main Forms in C# Apps[^]

The root problem, however, is that you may have left a thread running or some other thing is not being cleaned up when exiting the application. I would search out the real cause of the problem instead of trying band-aids and workarounds.

Your only friend in this is the debugger built in Visual Studio.


这篇关于应用程序关闭后未完全退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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