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 8956023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:41:33+00:00 2026-06-15T14:41:33+00:00

I have a simple WPF form with a textbox and button and on lost

  • 0

I have a simple WPF form with a textbox and button and on lost focus it simply simply shows a message box.
My code looks like this

   private void TextBox_LostFocus(object sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Lost Focus 1");
        Dispatcher.BeginInvoke(new Action(() =>
               {
                   //Uncomment below lines to get button click
                   //Thread.Sleep(100);
                   //System.Windows.Forms.Application.DoEvents();
                   MessageBox.Show("Lost focus");
               }
            ));
    }
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Button_Click");
    }

If my textbox has focus and when I click on button then Button click is not fired if the messagebox is shown but if I call Application.DoEvents() before I show messagebox then my button click get fired.

My actual application is bit more complex but I have tried to simulate this behavior with a simple textbox and a button. In actual application one of my background worker thread post on dispatcher to show a modal messagebox (or even WPF form) and any UI pending messages in queue seems to be handled by messagebox (I suspect) so for e.g. If I click on a canvas control Ideally I get “Mouse Down” and “Mouse Up” but if a Modal messagebox comes in between this 2 message then I only get “Mouse Down” and “Mouse Up” message is lost.

Note: I don’t see this behavior is not seen in case of Non-Modal dialogs.

Also just for my knowledge if someone can point me out on nice articles of how does windows forms handles windows message pump in case of Modal dialog and Non-Modal dialog would be helpful.

  • 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-15T14:41:34+00:00Added an answer on June 15, 2026 at 2:41 pm

    You can set the priority you want for your Dispatcher action using the DispatcherPriority parameter of the BeginInvoke() method. Lowest priority I usually use would be ApplicationIdle, thus allowing the Dispatcher to finish processing all its pending operations before processing yours.

    Dispatcher.BeginInvoke(new Action(() =>
    {
       MessageBox.Show("Lost focus");
    }), DispatcherPriority.ApplicationIdle);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF form where I'm trying to make a simple input form.
I have simple WPF layout task and looking to avoid code-behind if possible. I
I have a simple WPF application where I don't have any mvvm framework like
I have this simple code in a WPF application: ThreadStart start = delegate() {
I have a simple text box in a WPF application. I need to know
I have a WPF textbox on a form to allow input of a URI.
In my simple WPF application I use regular CheckBox control. It looks like I
I'm making my first foray into WPF - I have a simple form with
I have a simple WPF application that uses ClickOnce to handle installing. Within this
Say I have a very simple WPF grid (6 rows x 6 columns) defined

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.