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.