Question

I have an application all done in WPF, using MvvM/Prism/Unity and Remote as datasource.

I need a basic thing that on win forms is really easy, just check if the app is iddle after few minutes , and if is idle, lock the app and show the login screen.

After some search on google I ´ve found one solution that uses DllImport and another using pure Wpf methods.

I don´t know I , after I implemented the Wpf way (pls check the code below) it only works after I login into the app , if I open and click in a simple texbox or hit a search, the idle method is not fired, looks like there is something hanged in the background that makes Wpf idle routine to think that it´s doing something when it´s not.

How can I check all the services/methods/etc.. that are in memory related to may app ? callstack doesn´t show to much for me. I am affraid that or I am not calling in the correct way the remote services or I implemented something wrong on the props PropChanged events/observablecollections/etc...

Is there a better way to do this using 100% Wpf structure ?

private void CheckIdleTime()
{

    handler = delegate
    {
        DispatcherTimer timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromSeconds(5);
        timer.Tick += delegate
        {
            if (timer != null)
            {
                timer.Stop();
                timer = null;
                System.Windows.Interop.ComponentDispatcher.ThreadIdle -= handler;

                Console.WriteLine("IDLE! Lets logoff!");

                this.LockApplication();

                Console.WriteLine("logoff fired");

                System.Windows.Interop.ComponentDispatcher.ThreadIdle += handler;
            }

        };

        timer.Start();


        Dispatcher.CurrentDispatcher.Hooks.OperationPosted += delegate
        {
            if (timer != null)
            {
                timer.Stop();
                timer = null;
            }
        };
    };

    ComponentDispatcher.ThreadIdle += handler;
}
Was it helpful?

Solution

There will be default window events find the idle time... i think it will be wise if we use same events for wpf or any other applications...

following link will help you to implement it..

Application.Idle event not firing in WPF application

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top