c# - WinRT 定时注销

标签 c# windows-runtime windows-store-apps winrt-xaml

我正在开发 WinRT 应用程序。其中一项要求是该应用程序应具有“定时注销”功能。 这意味着在任何屏幕上,如果应用已闲置 10 分钟,应用应注销并导航回主屏幕。

这样做的蛮力方法显然是在每个页面的每个网格上连接指针按下事件,并在触发这些事件中的任何一个时重置计时器,但我想知道是否有更优雅、更可靠的方法这样做。

谢谢, 拉杰夫

最佳答案

通过使用 DispatcherTimer 和几个事件,您可以实现这一目标。

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.
}

关于c# - WinRT 定时注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18874516/

相关文章:

c# - Visual Studio 在异步调用异常时中断,而不是陷入 Catch() 中

c# - 使用属性生成自定义 setter

javascript - 如何将文件返回给用户?

c# - 取消 Item_Open 导致崩溃

windows-runtime - 如何使用 DataProtectionProvider?

c# - LAN 上的 Windows UWP Web 服务发现

c# - Task.CurrentId 是如何工作的?

xaml - 如何使用 MultiLine 和 Scroller 执行 WinRT TextBox

java - 是否可以在 Windows Phone 上的 C# 中运行 java 程序?

c# - 是否可以为这种类型的文本编写正则表达式?