Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 859025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:37:18+00:00 2026-05-15T08:37:18+00:00

I have a .NET Compact Framework app that can runs on three windows machines

  • 0

I have a .NET Compact Framework app that can runs on three windows machines (Desktop windows and two WinCE machines) and on the WinCE devices, the process never terminates on exit, even if I call Application.Exit(). Besides .NET, it uses one COM component (which does everything on the UI thread). If I break into the debugger after exitting, Visual Studio shows only one thread and a completely blank call stack.

What could possibly cause this?

Update: My process is terminating on the desktop but not the WinCE machines. I tried to force the process to terminate with the following code, but it doesn’t work:

[DllImport("coredll.dll")]
static extern int TerminateProcess(IntPtr hProcess, uint uExitCode);

static public void ExitProcess()
{
    if (Platform.IsWindowsCE)
        TerminateProcess(new IntPtr(-1), 0);
    Application.Exit();
}

There are also supposed to be ExitProcess() and GetCurrentProcess() APIs like the following, but if I try to call them, I get EntryPointNotFoundException. Therefore I am using TerminateProcess(-1, 0) because the documentation for the desktop version of GetCurrentProcess claims that it simply returns -1.

[DllImport("coredll.dll")]
static extern int ExitProcess(IntPtr hProcess);
[DllImport("coredll.dll")]
static extern IntPtr GetCurrentProcess();

Even throwing an unhandled exception won’t do it.

Update 2: the simplest program that causes the problem merely creates the COM object.

static void Main()
{
    new FastNavLib.MapControl();
}

C++ programs that use the COM component do not exhibit this behavior, so my C++ COM component must have some bizarre interaction with the .NET framework which I will investigate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:37:18+00:00Added an answer on May 15, 2026 at 8:37 am

    I sort-of figured it out.

    My COM object sets itself up to get WM_TIMER messages through a hidden window. Basically:

    // Register window class
    WNDCLASS wc;
    memset(&wc, 0, sizeof(wc));
    wc.lpfnWndProc = &WinCeTimerProc;
    wc.lpszClassName = _T("FastNavTimerDummyWindow");
    // Create window
    gTimerWindow = CreateWindow(wc.lpszClassName, wc.lpszClassName, 
        WS_OVERLAPPED, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), NULL);
    gTimerID = SetTimer(gTimerWindow, 88, gTimerIntervalMs, NULL);
    

    (Experts might point out I don’t need a timer window to receive timer messages–the last parameter of SetTimer can be set to a callback function. Indeed, if I use a callback instead of a timer window, the problem disappears! However, I had to use a timer window to work around a strange bug in WinCE in which SetTimer(NULL,...) can cause WM_TIMER messages to received by somebody that calls PeekMessage().)

    Now, when the last COM object that uses the timer is destroyed, the timer and timer window are also destroyed:

    KillTimer(gTimerWindow, gTimerID);
    DestroyWindow(gTimerWindow);
    

    Unfortunately, DestroyWindow() never returns. I assume there is some kind of deadlock in DestroyWindow, though it is not clear why the call stack is blank when I pause in Visual Studio. Perhaps because the COM object is destroyed automatically instead of by Marshal.ReleaseComObject(), it is destroyed in the finalizer thread, and DestroyWindow cannot be called from the finalizer thread on WinCE. As usual Microsoft doesn’t spell out the danger in its documentation, stating only “Do not use DestroyWindow in one thread to destroy a window created by a different thread.”

    The solution was simple: don’t destroy the timer window at all, as the OS destroys it automatically when the process exits.

    Fun fact: the problem with DestroyWindow does not occur if I call SetTimer(NULL,...) instead of SetTimer(gTimerWindow,...), but it does occur if I don’t call SetTimer at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .Net Compact app running on Windows Mobile, and I want to
I'm developing a Windows Mobile WinForm app with C# and .Net Compact Framework 2.0
I have a .NET 2.0 windows forms app, which makes heavy use of the
I have a .NET webforms front end that allows admin users to upload two
Working in .NET Compact Framework, C#, .Net 3.5, Visual Studio 2008. Targeting Windows Mobile
We've got a Model-View-Presenter setup with our .NET Compact Framework app. A standard CF
If I have .Net Form with a component/object such as a textbox that I
I have a .Net desktop application with a TreeView as one of the UI
I have a .NET 2.0 application that has recently had contributions that are Service
I have a .NET 2.0 Windows Forms application. Where is the best place the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.