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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:32:55+00:00 2026-06-14T04:32:55+00:00

I want an auto logoff feature in my WPF application and have implemented it

  • 0

I want an auto logoff feature in my WPF application and have implemented it with hooks. However whenever the mouse is over the application, the performance freezes, degrades and becomes unbearably unresponsive. Once the mouse is off the window performance goes back to normal. If I turn the auto logoff off, performance is fine always, so it’s definitely this causing it. Any idea how to do it different to avoid this?

private void InitializeAutoLogoffFeature()
        {
            //var windowSpecificOSMessageListener = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
            //if (windowSpecificOSMessageListener != null)
            //    windowSpecificOSMessageListener.AddHook(CallBackMethod);

            //AutoLogOffHelper.LogOffTime = _viewModel.logOffTime;
            //AutoLogOffHelper.MakeAutoLogOffEvent += AutoLogOffHelper_MakeAutoLogOffEvent;
            //AutoLogOffHelper.StartAutoLogoffOption();
            AutoLogOffHelper
        }

private static IntPtr CallBackMethod(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            try
            {
                //  Listening OS message to test whether it is a user activity
                if ((msg >= 0x0200 && msg <= 0x020A) || (msg <= 0x0106 && msg >= 0x00A0) || msg == 0x0021)
                {
                    AutoLogOffHelper.ResetLogoffTimer();
                }
                else
                {
                    // For debugging purpose
                    // If this auto logoff does not work for some user activity, you can detect the integer code of that activity  using the following line.
                    //Then All you need to do is adding this integer code to the above if condition.
                    Debug.WriteLine(msg.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageHelper.LogError(ex);
            }

            return IntPtr.Zero;
        }



class AutoLogOffHelper
    {
        static System.Windows.Forms.Timer _timer;
        public static int LogOffTime { get; set; }

        public delegate void MakeAutoLogOff();
        static public event MakeAutoLogOff MakeAutoLogOffEvent;

        static public void StartAutoLogoffOption()
        {
            System.Windows.Interop.ComponentDispatcher.ThreadIdle += DispatcherQueueEmptyHandler;
        }

        static void _timer_Tick(object sender, EventArgs e)
        {
            if (_timer == null) return;

            System.Windows.Interop.ComponentDispatcher.ThreadIdle -= DispatcherQueueEmptyHandler;
            _timer.Stop();
            _timer = null;

            if (MakeAutoLogOffEvent != null)
            {
                MakeAutoLogOffEvent();
            }
        }

        static void DispatcherQueueEmptyHandler(object sender, EventArgs e)
        {
            if (_timer == null)
            {
                _timer = new System.Windows.Forms.Timer
                             {
                                 Interval = LogOffTime * 60 * 1000
                             };

                _timer.Tick += _timer_Tick;
                _timer.Enabled = true;
            }
            else if (_timer.Enabled == false)
            {
                _timer.Enabled = true;
            }
        }

        static public void ResetLogoffTimer()
        {
            if (_timer == null) return;
            _timer.Enabled = false;
            _timer.Enabled = true;
        }

    }
  • 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-14T04:32:57+00:00Added an answer on June 14, 2026 at 4:32 am

    Try taking your debug.writeline out – It’s very slow and since you might be dealing with a lot of events, it could easily be the problem.

    Failing that, have you tried using the profiler to see what’s eating up resources?

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

Sidebar

Related Questions

I have an asp.net web application. I want to auto log in a user
I have a form that i want to auto populate the last 2 fields
I have a simple form on a page and I want to auto submit
I have a number stored in an NSMutableString instance which I want to auto
I have Auto completed text view,i want to filter the items present in the
I have a plist that I want to auto-populate the version number of the
I have a form with a input box that I want to auto-complete with
I have a cell with the format mm/dd/yyyy hh:mm:ss. I want to auto increment
I have a primary key that I don't want to auto increment (for various
I have a simple Java question here. I want to auto text scroll to

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.