Search code examples
c#compact-frameworkwindows-ce

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#.

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.


Solution

  • 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.