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

  • Home
  • SEARCH
  • 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 9303261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:26:38+00:00 2026-06-18T23:26:38+00:00

I am developing a wpf application using the prism framework [.net 4.0]. I have

  • 0

I am developing a wpf application using the prism framework [.net 4.0]. I have implemented a popup window using the RegionPopupBehavior from the StockTrader RI. Now when I close the main window either using the close button in upper right of window title bar [main window], or using

Application.Current.Shutdown() 

call in a button click, I get a win32 exception with the message “Invalid Window Handle” and the stack trace is all interop calls back to the app Run() call.

I have search google and SO for answer to no avail. I have set break during close and checked the Windows collection but it only shows the main window as active [if popup is hidden]. Note that I get the error whether the popup window is open or not when I hit close.

Here is the stack trace:

at MS.Win32.HwndWrapper.DestroyWindow(Object args)
   at MS.Win32.HwndWrapper.Dispose(Boolean disposing, Boolean isHwndBeingDestroyed)
   at MS.Win32.HwndWrapper.Dispose()
   at System.Windows.Interop.HwndSource.Dispose(Boolean disposing)
   at System.Windows.Interop.HwndSource.WeakEventDispatcherShutdown.OnShutdownFinished(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.Dispatcher.ShutdownImpl()
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at RNDGroup.App.App.Main() in c:\Users\jgilliland\Projects\Common\Source\Prism GUI\RNDGroup.App\obj\x86\Release\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

my question is either how do I fix this if anyone has seen it before in similar circumstances, or how do I go about debugging this win32 exception further? Thanks, j

  • 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-06-18T23:26:39+00:00Added an answer on June 18, 2026 at 11:26 pm

    The technical lead on my team found the problem and removed this error. The popup region is being used to show/hide or rather activate/deactivate the VirtualKeyboardView in its own window. The occurrence of the “invalid window handle” win32 exception began when I switched from showing the keyboard when the user clicked a button, to showing the keyboard whenever a textbox gets focus.

    The focus events are a little funny, I was seeing what amounted to multiple focus events for the same click/focus by the user. Anyways, the end of the story is that I realized the issue was repeated focus events but I could not find the source of the problem. My teammate was able to track down an issue of recursion that arose from these seemingly repeated focus events for the textbox. The solution was to track the last textbox element that caused the keyboard to be shown and essentially ignore the repeated focus events. This removed the win32 exception for invalid window handle.

    I know that this was an odd question and an even odder answer, but it is the very first time I have posted a question in a forum like this and I obviously need to learn how to better ask the question in the first place. But, thanks to my wonderfully helpful team lead, I was able to get rid of the error and move on with the implementation of this virtual keyboard in wpf in a secondary popup region. It has been a learning experience all the way around.

    Here is some code that might help clarify the answer. This is from the VirtualKeyboardService that manages showing and hiding the keyboard view.

    /// <summary>
    /// Opens the keyboard.
    /// </summary>
    public void OpenKeyboard()
    {
        lock (_lock)
        {
            // allow for ignoring a refocus one time
            if (_ignoreOnce)
            {
                _ignoreOnce = false;
                return;
            }
            // open keyboard if not already open
            if (!_isKeyboardOpen)
            {
                var viewName = typeof(VirtualKeyboardView).FullName;
                _regionManager.RequestNavigate(RegionNames.PopupRegion, new Uri(viewName, UriKind.Relative));
                _isKeyboardOpen = true;
                _lastImpression = null;
            }
        }
    }
    

    And this is the method that closes the virtual keyboard, this is called from the keyboard’s view model when the user clicks a close button, or when they hit the enter, tab, or esc key. It is also called from an event handler for the MainWindow’s Activated event.
    ///
    /// Closes the keyboard.
    ///
    /// if set to true [revert text].
    public void CloseKeyboard(bool revertText = false)
    {
    lock (_lock)
    {
    // close the keyboard view
    var view = _regionManager.Regions[RegionNames.PopupRegion].ActiveViews.FirstOrDefault();

            if (view != null)
            {
                _regionManager.Regions[RegionNames.PopupRegion].Deactivate(view);
                _isKeyboardOpen = false;
                _lastImpression = CurrentTarget;
            }
    
            // revert text if needed
            if (revertText && CurrentTarget != null)
            {
                CurrentTarget.Text = CurrentText;
            }
        }
    }
    

    That was tricky too, that is where the ignore once comes into play. I had to be able to close the keyboard view when the user clicked “away” which activates the mainwindow, which is likely focused on a textbox, which caused the keyboard view to reappear. Ignore once option allows breaking out of that loop. There were a lot of different use cases involved in automatically showing a virtual keyboard. I learned a lot about using behaviors and composite commands in wpf…

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

Sidebar

Related Questions

I'm developing a .NET 4.0 application using PRISM and MVVM, as well as WPF.
I'm developing client-server application by using .Net, C#, WCF, WPF. And now I need
I have an application which I am developing using WPF\Prism\MVVM. All is going well
We have a wpf application in .Net Framework 4 and using SQL Server Express
I'm developing WPF Prism application using Unity container. The issue is: I have a
I am developing a WPF application (using MVVM) and have implemented IDataErrorInfo on my
I'm developing a WPF application using MVVM. Inside a Window, I have a control
I'm developing an application using the WAF (WPF Application Framework) which is based on
i'm developing an application (wpf) that have 3 windows. in the main window user
I am developing a rich client application using WPF-PRISM-MVVM. The client interacts with a

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.