惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
罗磊的独立博客
小众软件
小众软件
I
InfoQ
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
MyScale Blog
MyScale Blog
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
博客园 - 司徒正美
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
N
Netflix TechBlog - Medium

博客园 - Peter Zhang

TF42064: The build number already exists for build definition error in TFS2010 模拟ORACLE wm_concat函数(把一列中的多行数据在一行显示) [转]重建损坏的Windows Management Instrumentation(WMI)服务 .NET 程序内存占用问题 存储过程锁问题、存储过程编译锁问题 ORA-00054错误解决方案 Oracle循环语句 【转】物化视图刷新 Oracle查询条件带有汉字时查询不出数据的原因 ORA-01658: 无法为表空间中段创建 INITIAL 区 Oracle未启用Partitioning功能 Oracle 表空间 Redmine running under Mongrel as windows service Redmine 插件安装 Redmine 如何使用版本库 Redmine 配置 Redmine EMAIL /SMTP 服务器设置 redmine svn:issuer is not trusted 问题的解决办法 redmine 1.2.1安装和安装会出现的问题
获取系统闲置时间
Peter Zhang · 2012-08-27 · via 博客园 - Peter Zhang
 
http://www.pinvoke.net/default.aspx/user32.GetLastInputInfo
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO
{
  [MarshalAs(UnmanagedType.U4)]
  public int cbSize;
  [MarshalAs(UnmanagedType.U4)]
  public uint dwTime;
}

static class NativeMethods
{
   /// <summary>
   /// 获取上一次输入的时间。
   /// </summary>
   /// <param name="plii"></param>
   /// <returns>true:获取成功。false:获取失败。</returns>
   [DllImport("user32.dll")]
   public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
   /// <summary>
   /// 获取上一次操作后的闲置时间。
   /// </summary>
   /// <returns>闲置时间的毫秒数。</returns>
    public static long GetIdleTick()
    {
         LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
         vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
         if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
         return Environment.TickCount - (long)vLastInputInfo.dwTime;
    }
}