WinRT定时注销 [英] WinRT timed logout

查看:125
本文介绍了WinRT定时注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序WinRT的。其中一项要求是,应用程序应该有一个计时注销功能。
这意味着,任何屏幕上,如果应用已经闲置了10分钟,应用程序应该退出,然后返回到主屏幕。



显然这样做的蛮力的方法是挂钩的指针压在每一页上的每一个网格的事件,如果这些事件被触发复位定时器,但我不知道是否有这样做的更优雅,更可靠的方式



谢谢,
拉杰夫


解决方案

随着使用 DispatcherTimer &安培; 。几个事件,你可以做到这一点。



<预类=郎CSHARP prettyprint-覆盖> DispatcherTimer定时器;
私人无效InitializeTimer()
{
Dispatcher.AcceleratorKeyActivated + = Dispatcher_AcceleratorKeyActivated;
Window.Current.CoreWindow.PointerMoved + = CoreWindow_PointerMoved;
Window.Current.CoreWindow.PointerPressed + = CoreWindow_PointerPressed;

定时器=新DispatcherTimer();
Timer.Interval = TimeSpan.FromMinutes(10);
Timer.Tick + = Timer_Tick;
Timer.Start();
}

私人无效CoreWindow_PointerPressed(CoreWindow发件人,PointerEventArgs参数)
{
Timer.Start();
}

私人无效CoreWindow_PointerMoved(CoreWindow发件人,PointerEventArgs参数)
{
Timer.Start();
}

私人无效Dispatcher_AcceleratorKeyActivated(CoreDispatcher发件人,AcceleratorKeyEventArgs参数)
{
Timer.Start();
}

私人无效Timer_Tick(对象发件人,对象E)
{
Timer.Stop();
// TODO:不要注销。
}


I am developing a WinRT app. One of the requirements is that the app should have a "timed logout" feature. What this means is that on any screen, if the app has been idle for 10 mins, the app should logout and navigate back to the home screen.

The brute force way of doing this obviously would be to hook up pointer pressed events on every grid of every page and resetting the timer if any of these events is fired but I was wondering if there was a more elegant and more reliable way of doing this.

Thanks, Rajeev

解决方案

With the use of DispatcherTimer & several events you can achieve that.

DispatcherTimer Timer;
private void InitializeTimer()
{
    Dispatcher.AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated;
    Window.Current.CoreWindow.PointerMoved += CoreWindow_PointerMoved;
    Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;

    Timer = new DispatcherTimer();
    Timer.Interval = TimeSpan.FromMinutes(10);
    Timer.Tick += Timer_Tick;
    Timer.Start();
}

private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
{
    Timer.Start();
}

private void CoreWindow_PointerMoved(CoreWindow sender, PointerEventArgs args)
{
    Timer.Start();
}

private void Dispatcher_AcceleratorKeyActivated(CoreDispatcher sender, AcceleratorKeyEventArgs args)
{
    Timer.Start();
}

private void Timer_Tick(object sender, object e)
{
    Timer.Stop();
    //TODO: Do logout.
}

这篇关于WinRT定时注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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