不活动和活动,应用程序空闲,用户不活动自动注销 [英] Inactivity and activity ,application idle , user-inactivity auto logout

查看:91
本文介绍了不活动和活动,应用程序空闲,用户不活动自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量的搜索并花费了4个小时,我认为这是查找用户非活动状态并锁定屏幕的最佳方法.

After lot of googling and spending 4 hours I guess this is the best way to find user inactive and lock screen.

public MainWindow()
    {
        InitializeComponent();
        var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(10) };
        timer.Tick += delegate
        {
            timer.Stop();
            MessageBox.Show("Logoff trigger");
            timer.Start();
        };
        timer.Start();
        InputManager.Current.PostProcessInput += delegate(object s, ProcessInputEventArgs r)
        {
            if (r.StagingItem.Input is MouseButtonEventArgs || r.StagingItem.Input is KeyEventArgs)
                timer.Interval = TimeSpan.FromSeconds(10);
        };
    }

推荐答案

如果您的问题是:有没有更好的方法来实现会话超时?" -然后,我可能会说-这就是我的做法.

If your question is, "Is there a better way to implement a session timeout?" - then I would say, possibly - this is how I do it.

会话超时可以执行以下两项操作之一.它可以像街机游戏一样工作,在该游戏中您有超时时间来完成任务.或者它可以监视不活动状态并在没有任何反应的情况下关闭.

A session timeout can do one of two things. It can work like an arcade game where you have a timeout duration in which to complete your tasks. Or it can monitor for inactivity and close if nothing happens.

无论哪种方式,我都会将此功能包装到会话提供程序中-假设以MVVM为目标,我将使用提供程序来引用某种服务或数据源.

Either way, I would wrap this functionality into a session provider - assuming MVVM is the goal, I use provider to refer to a service or data source of some sort.

该提供程序被实例化为一个单例,因此在整个应用程序生命周期中作为一个实例存在.我通常通过在app.xaml中创建它来进行管理.然后,我使用诸如MVVM light之类的消息框架与提供程序进行交互.

The provider gets instantiated as a singleton and so exists as one instance throughout the app life cycle. I usually manage this by creating it in app.xaml. I then interact with the provider using a message framework such as MVVM light.

创建后,提供者将管理一个线程,该线程将检查日期时间以查看其是否过去.如果确实如此,它将通过事件或消息发出会话.此消息由您的应用程序接收以关闭或关闭.

Once created the provider manages a thread which checks a datetime to see if it occurs in the past. If it does it issues a session over event or message. This message is picked up by your application to shut down or whatever.

如果需要有限的时间段或时间,则可以实现一条开始消息,该消息根据要运行的时间跨度将受监视的日期时间设置为将来的某个时间点.如果您希望不活动注销,则可以从您认为合适的任何用户交互中发送此消息,以防止注销,例如输入更改或ICommand执行.

If you want a finite period or time, you implement a start message which sets the monitored date time to a point in the future according to the time span you want to run. If you want an inactivity log out then you send this message from whatever user interactions you see fit to prevent log out such as input changes or ICommand executes.

我更进一步,所以我的提供者还会在超时完成前几秒钟发出结束"消息,以便我可以显示警告-但希望您能理解.

I take this a stage further so my provider also issues an 'ending' message a few seconds before the timeout completes so I can display a warning - but hopefully you get the general idea.

如果这听起来像您想要的那样,那么我将在一些示例中添加,但是到目前为止,如果不是您要的内容,那么您还可以.

If this sounds like what you're after then I will add in some examples, but haven't so far in case this is not what you're asking.

这篇关于不活动和活动,应用程序空闲,用户不活动自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆