tags:

views:

977

answers:

3

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
         }
    }
A: 

See this CodeProject article:

Detecting Application Idleness

David
A: 

How about subscribing to SENS events?

Here's another link.

Sergey Aldoukhov
I would like to control everything internally without calling/querying an external service.
paradisonoir
A: 

See this StackOverflow answer to another question regarding idle time for a nice solution.

cdiggins