获取活动/空闲时间在WPF应用程序 [英] Getting inactivity/idle time in a WPF application

查看:208
本文介绍了获取活动/空闲时间在WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找最好的办法,找出如果我的用户在我的WPF应用程序闲置。目前,我从操作系统这个空闲时间,如果他们最小化应用程序,并去在互联网搜索,有一个在操作系统的过程,所以操作系统并没有认为这是不活动的时间,即使他们没有做在应用程序内任何东西。不过,我想看看他们有没有点击或做我的应用程序内部的任何物件。



这是我怎么可以在空闲时间现在。

  myApplication.MainMethod()
{
System.Windows.Forms.Timer myTimer =新系统。 Windows.Forms.Timer();
myTimer .Interval = 1000;
myTimer .Tick + =新的EventHandler(Timer_Tick);
myTimer。开始();
}

无效Timer_Tick(对象发件人,EventArgs五)
{
INT IDLETIME =(int)的Win32.GetIdleTime();
如果(IDLETIME< certainNumber)
{
//这样做
}
}


解决方案

 公共主窗口()
{
的InitializeComponent();
ComponentDispatcher.ThreadIdle + =新System.EventHandler(ComponentDispatcher_ThreadIdle);
}

无效ComponentDispatcher_ThreadIdle(对象发件人,EventArgs五)
{
//做你闲置的东西在这里
}


I was looking for the best approach to find out the if my users are idle in my WPF application. Currently, I take this idle time from operating system, and if they minimize the application, and go and search in Internet, there is a process in the operating system, so Operation system does not consider this as inactivity time even though they are not doing anything inside the application. However, I would like to find out if they have not clicked or do anything inside my application.

This is how I can that idle time right now.

myApplication.MainMethod()
    {
        System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
        myTimer .Interval = 1000;
        myTimer .Tick += new EventHandler(Timer_Tick);
        myTimer .Start();
    }

    void Timer_Tick(object sender, EventArgs e)
    {
        int idleTime= (int)Win32.GetIdleTime();
        if (idleTime<certainNumber)
        {
         //do this
         }
    }

解决方案

public MainWindow()
    {
        InitializeComponent();
        ComponentDispatcher.ThreadIdle += new System.EventHandler(ComponentDispatcher_ThreadIdle);
    }

void ComponentDispatcher_ThreadIdle(object sender, EventArgs e)
    {
        //do your idle stuff here
    }

这篇关于获取活动/空闲时间在WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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