سلام بر همه برنامه نویسان این مرز و بوم! امروز کد به دست آوردن مدت زمان بیکار بودن سیستم با c#.net رو براتون آماده کردم.
struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
public static uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
return ((uint)Environment.TickCount - lastInPut.dwTime);
}
: طرز استفاده
private Timer CheckIdleTimer;
private void Form1_Load(object sender, System.EventArgs e)
{
CheckIdleTimer = new Timer();
{
public uint cbSize;
public uint dwTime;
}
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
public static uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
return ((uint)Environment.TickCount - lastInPut.dwTime);
}
: طرز استفاده
private Timer CheckIdleTimer;
private void Form1_Load(object sender, System.EventArgs e)
{
CheckIdleTimer = new Timer();