[英]Terminate Application on exit in Windows CE 6.0
I'm running Windows CE 6.0
on an ARM processor device using .NET CF 2.0 SP2
with an application written in C#
. 我在ARM处理器设备上运行
Windows CE 6.0
,使用.NET CF 2.0 SP2
和一个用C#
编写的应用程序。
I'm experiencing a problem where my application continues to run after it has closed. 我遇到一个问题,我的应用程序在关闭后继续运行。 The application opens a connection with something connected to the device and doesn't release it until properly closed.
应用程序打开与设备连接的连接,并且在正确关闭之前不会释放它。 Because of this, I cannot reopen and use the application while it continues to run and I can't run other applications which wish to use the attached device either.
因此,我无法在继续运行时重新打开并使用该应用程序,并且我无法运行其他希望使用所连接设备的应用程序。
I have tried to run Application.Exit()
and all of my threads have the IsBackground
property set to true
but this doesn't work. 我试图运行
Application.Exit()
并且我的所有线程都将IsBackground
属性设置为true
但这不起作用。 After closing the application I can use a task manager and see that the process continues to run. 关闭应用程序后,我可以使用任务管理器,看到该过程继续运行。
I'd normally use Environment.Exit()
but this is not available in CF, unfortunately. 我通常使用
Environment.Exit()
但遗憾的是,这在CF中不可用。
Is there any of methods I can try and use or causes that would be making this happen? 有没有我可以尝试使用的方法或导致这种情况发生的原因?
Thanks. 谢谢。
You could try something like this: 你可以尝试这样的事情:
Process thisProcess = Process.GetCurrentProcess();
thisProcess.Kill();
And see what happens. 看看会发生什么。 It's obviously not ideal to closing a application, but it might work as a last resort, especially if you're handling the saving and discarding of data manually prior to that anyway.
关闭应用程序显然不是理想的,但它可能作为最后的手段,特别是如果您在此之前手动处理数据的保存和丢弃。
For anyone still struggling with this: 对于仍在努力解决这个问题的人:
I found the problem was that with Windows CE / WEHH / .NET Compact, applications don't exit on pressing the X button on a form, they are only minimized (meaning the closing event doesn't get called). 我发现问题在于,使用Windows CE / WEHH / .NET Compact时,应用程序不会在按下表单上的X按钮时退出,它们只会被最小化(意味着不会调用关闭事件)。
As per one of the answers on this page, the close button can be changed to actually exit the application by setting the form property 'MinimizeBox' to false. 根据此页面上的其中一个答案,可以通过将表单属性“MinimizeBox”设置为false来更改关闭按钮以实际退出应用程序。
this.MinimizeBox = false;
This will change the X button to an OK button, and will exit the application completely. 这会将X按钮更改为OK按钮,并完全退出应用程序。
May be this can Help. 可能这可以帮助。 Set Thread's Background Property to false before calling Application.exit() ;
在调用Application.exit()之前将Thread的Background属性设置为false ;
private void BtnExit_Click(object sender, EventArgs e)
{
Thread1.IsBackground = false;
Thread2.IsBackground = false;
Application.exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.