I’ve inherited some windows-mobile code that I’ve been bringing up-to-date. I’ve come across a weird bug, and I was hoping that even though a bit vague, maybe it will spark someone’s memory:
Running the app (which is basically a glorified Forms app with P/Invoke gps code), I switch to the task manager, and close the app via End Task. Seems to exit fine (no errors and disappears from Task Manager). Unfortunately, the app refuses to start a second time until I reboot the phone or reinstall the CAB.
What’s worse: this bug is reproducible on a HTC Diamond, but works fine (ie. can run again after EndTask) on an HTC HD2.
The only thing I can think of is some kind of timing race between a Dispose() and the Task Manager. Any ideas?
I’m also thinking of a workaround – I do have a working “Exit Application” routine that correctly cleans up the app; can I catch the EndTask event in the c# code in order to complete a proper cleanup?
Maybe I’m just missing the pain point… all ideas welcome 🙂
When you use TaskManager to close it, the following happens:
If you have a worker thread running that does not exit, the process will often not fully terminate. This was really common in CF 1.0 where the IsBackground property for a thread didn’t exist.
Since TaskManager only enumerates Form captions, if your forms are all closed, it will not show the app, even through the process is running. When you try to execute again, the shell detects that it’s already running and simply swithes to the running (with no UI) process so it looks like nothing happened.
You can verify this behavior with Remote Process Viewer.
The solution is to fix your worker thread code to exit properly. Typically I use a boolean or a WaitHandle to signal that they should exit. Setting IsBackground to true should also happen for all threads that are created.