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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:39:57+00:00 2026-05-20T08:39:57+00:00

I have a WPF application that has several modal window used for various purposes.

  • 0

I have a WPF application that has several modal window used for various purposes. This is easily accomplished by using the ShowDialog function. However, in my application I have a timer to measure idle time (i.e. no mouse moves or key strokes) that will cause the user to be logged off. Is there a way (when this timer fires) to find and close all open modal windows without tracking each explicitly?

Update
I would also like to close any MessageBox.Show instances. Is this possible?

Thanks,
Matt

  • 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-20T08:39:58+00:00Added an answer on May 20, 2026 at 8:39 am

    Is there a way (when this timer fires) to find and close all open modal windows without tracking each explicitly?

    You could use ComponentDispatcher.IsThreadModal to check to see if you’re UI thread is in a modal state. If it is, the Application.Current.Windows property will give you the list of opened Windows.

    If you only have a single MainWindow, you could close any others (as they’d be your modal dialogs), but if you have multiple windows, you’d have to check each one.

    Unfortunately, there’s no direct API to determine whether a specific Window is modal – but there is a private variable in the Window class you could use to do this. For example, the following method uses reflection to determine whether a Window is modal:

      public static bool IsModal(Window window)
      {
           Type type = typeof(Window);
           var field = type.GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic);
           return field.GetValue(window);
      }
    

    This is, unfortunately, subject to change (since it’s using undocumented private members).

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

Sidebar

Related Questions

I have a WPF application that runs fine under XP as an administrator. When
I have written a WPF application that I want to port to Silverlight 2.
I have a simple message box in a WPF application that is launched as
I have a WPF application using Aero Glass. When using the application under a
I have a very simple WPF application in which I am using data binding
I have a FlowDocument in a standard WPF application window where I have some
I have a WPF application in VS 2008 with some web service references. For
Please help! Background info I have a WPF application which accesses a SQL Server
I have a simple WPF application which I am trying to start. I am
I have a simple WPF application with a menu. I need to add menu

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.