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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:14:58+00:00 2026-06-09T06:14:58+00:00

Issue: I have a WPF fullscreen application, which acts as a dashboard. The computer

  • 0

Issue:
I have a WPF fullscreen application, which acts as a dashboard. The computer is in domain and domain policies enforce the computer to be locked in 10 minutes after the last user activity. I want to prevent the workstation (or desktop) from locking automatically.
An example of such behavior: Windows Media Player, which prevents this while a movie is running.

Known solutions (kinda workarounds):

  1. It is possible to send a Win32 Mouse Move event every fixed interval of time (for example, every minute)
  2. It is possible to send a key to the program (for example “Left Shift” key up) every fixed interval of time (for example, every minute)

QUESTION:
How can I prevent windows workstation from locking without using these workarounds?

Disclaimer:
I was pretty sure, there should be a similar question answered somewhere on StackOverflow, but i didn’t find any. I would appreciate, if you could point me into the right direction.

  • 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-09T06:15:00+00:00Added an answer on June 9, 2026 at 6:15 am

    The solution has been pointed out through the comments, but I’m providing a simple starter solution for anyone else arriving via a web search:

    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
    
        public App()
        {
            InitializeComponent();
    
            App.Current.Startup += new StartupEventHandler((sender, e) =>
                {
                    SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
                });
            App.Current.Exit += new ExitEventHandler((sender, e) =>
                {
                    SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
                });
        }
    }
    
    [FlagsAttribute]
    public enum EXECUTION_STATE : uint
    {
        ES_AWAYMODE_REQUIRED = 0x00000040,
        ES_CONTINUOUS = 0x80000000,
        ES_DISPLAY_REQUIRED = 0x00000002,
        ES_SYSTEM_REQUIRED = 0x00000001
        // Legacy flag, should not be used.
        // ES_USER_PRESENT = 0x00000004
    }
    

    An alternative place to put the logic would be within an event handler for StateChanged on your main application window:

    this.StateChanged += new EventHandler((sender, e) =>
        {
            if (WindowState == System.Windows.WindowState.Maximized)
            {
                SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
            }
            else
            {
                SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses WPF Composite, and I have an issue. I've
I have an action Edit in my WPF application, which is bound to items
I have a WPF application which presents a list of items. I would like
We have a WPF application which gets data from an Analysis Services Cube. The
I have a WPF application developed against the MVVM framework in which the ViewModel
Please help! Background info I have a WPF application which accesses a SQL Server
I'm developing WPF Prism application using Unity container. The issue is: I have a
I have a WPF application that has a variable x which is an instance
I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and
I have a very basic databinding issue with the Visifire WPF charting tool in

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.