internal override void RemoveReflectChild() { if (--_childCount < 0) { Debug.Fail("How did parkingwindow childcount go negative???"); _childCount = 0; } if (_childCount != 0 || !IsHandleCreated) { return; } // Check to see if we are running on the thread that owns the parkingwindow. // If so, we can destroy immediately. // // This is important for scenarios where apps leak controls until after the // messagepump is gone and then decide to clean them up. We should clean // up the parkingwindow in this case and a postmessage won't do it. uint id = User32.GetWindowThreadProcessId(HandleInternal, out _); ThreadContext context = ThreadContext.FromId(id); // We only do this if the ThreadContext tells us that we are currently // handling a window message. if (context is null || !ReferenceEquals(context, ThreadContext.FromCurrent())) { User32.PostMessageW(HandleInternal, (User32.WM)WM_CHECKDESTROY); }