2

I have a simple application, I want to close it if the user does nothing in 10 minutes. I try use timer and stopwatch but I can't solve it.

[DllImport("user32.dll")]
public static extern Boolean GetLastInputInfo(ref tagLASTINPUTINFO plii);

public struct tagLASTINPUTINFO
{
    public uint cbSize;
    public Int32 dwTime;
}

private void counter_idle_time_step2_Tick(object sender, EventArgs e)
{
    tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO();
    Int32 IdleTime;
    LastInput.cbSize = (uint)Marshal.SizeOf(LastInput);
    LastInput.dwTime = 0;

    if (GetLastInputInfo(ref LastInput))
    {
        IdleTime = System.Environment.TickCount - LastInput.dwTime;
        if (lg_st2.counter_time_logout == (IdleTime / 1000))
        {
            this.Close();
            lg_st2.Show();
        }
    }
}

How can I do it. Please show me some sample for this.

Zong
  • 6,160
  • 5
  • 32
  • 46
user3050564
  • 29
  • 1
  • 1
  • 5

1 Answers1

0

I dont understand much of your code, but one thing I see is that line:

if (lg_st2.counter_time_logout == (IdleTime / 1000))

In the moment you just say: If did nothing for exactly 10 Minutes, then close. (If it´s 10 min and 1 sec, it wont work) But, what you want to say is that:

if (lg_st2.counter_time_logout <= (IdleTime / 1000))

With this line It should work. Sorry if it doesn´t.

Greetings Björn

Bio42
  • 389
  • 3
  • 18