4

I'm running Windows CE 6.0 on an ARM processor device using .NET CF 2.0 SP2 with an application written in 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. 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.

Is there any of methods I can try and use or causes that would be making this happen?

Thanks.

4

3 回答 3

5

你可以尝试这样的事情:

Process thisProcess = Process.GetCurrentProcess();
thisProcess.Kill();

看看会发生什么。关闭应用程序显然并不理想,但它可能是最后的手段,特别是如果您在此之前手动处理数据的保存和丢弃。

于 2013-10-30T00:50:05.417 回答
1

对于仍在为此苦苦挣扎的人:

我发现问题在于,使用 Windows CE / WEHH / .NET Compact,应用程序不会在按下表单上的 X 按钮时退出,它们只会被最小化(这意味着不会调用关闭事件)。

根据页面上的答案之一,可以通过将表单属性“MinimizeBox”设置为 false 来更改关闭按钮以实际退出应用程序。

this.MinimizeBox = false;

这会将 X 按钮更改为 OK 按钮,并完全退出应用程序。

于 2016-01-17T23:36:56.067 回答
0

可能这可以帮助。在调用Application.exit()之前将 Thread 的 Background 属性设置为false

private void BtnExit_Click(object sender, EventArgs e)
{
  Thread1.IsBackground = false;
  Thread2.IsBackground = false;

  Application.exit();
}
于 2014-12-29T12:10:25.967 回答