[Csharp]
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Namespace VistaRenderer
{
Public partial class FrmTestTimeout: Form
{
Public FrmTestTimeout ()
{
InitializeComponent (); // this. timer1 = new System. Windows. Forms. Timer (this. components );
}
Private void FrmTestTimeout_Load (object sender, EventArgs e)
{
Timer1.Enabled = true;
Timer1.Interval = 2*1000; // timer trigger interval of 2 seconds
This. timer1.Tick + = new EventHandler (timerstmtick );
}
/// <Summary>
/// Timer triggered
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Void timereffectick (object sender, EventArgs e)
{
// The last input time is greater than 5 seconds.
If (GetLastInputTime ()> = 5*1000)
{
MessageBox. Show ("time out"); // write timeout is allowed here. For example, a lock window is displayed.
}
}
[StructLayout (LayoutKind. Sequential)]
Struct LASTINPUTINFO
{
[Financialas (UnmanagedType. U4)]
Public int cbSize;
[Financialas (UnmanagedType. U4)]
Public uint dwTime;
}
[DllImport ("user32.dll")]
Static extern bool GetLastInputInfo (ref LASTINPUTINFO plii );
/// <Summary>
/// Obtain the interval from the last operation
/// </Summary>
/// <Returns> </returns>
Static long GetLastInputTime ()
{
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO ();
VLastInputInfo. cbSize = Marshal. SizeOf (vLastInputInfo );
If (! GetLastInputInfo (ref vLastInputInfo) return 0;
Return Environment. TickCount-(long) vLastInputInfo. dwTime;
}
}
}