实现程序多长时间没有接受到用户的消息
2007-03-09 15:00
253 查看
1 private void Form1_Load(object sender, EventArgs e)
2 {
3 System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
4 t.Interval = 100;
5 t.Tick += new EventHandler(t_Tick);
6 t.Start();
7 }
8
9 void t_Tick(object sender, EventArgs e)
10 {
11 long time = GetLastInputTime();
12 if (time > 1000)
13 {
14 ((System.Windows.Forms.Timer)sender).Stop();
15 MessageBox.Show(time.ToString());
16 }
17 }
18
19 [StructLayout(LayoutKind.Sequential)]
20 struct LASTINPUTINFO
21 {
22 [MarshalAs(UnmanagedType.U4)]
23 public int cbSize;
24 [MarshalAs(UnmanagedType.U4)]
25 public uint dwTime;
26 }
27
28 [DllImport("user32.dll")]
29 static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
30
31 static long GetLastInputTime()
32 {
33 LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
34 vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
35 if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
36 return Environment.TickCount - (long)vLastInputInfo.dwTime;
37 }
2 {
3 System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
4 t.Interval = 100;
5 t.Tick += new EventHandler(t_Tick);
6 t.Start();
7 }
8
9 void t_Tick(object sender, EventArgs e)
10 {
11 long time = GetLastInputTime();
12 if (time > 1000)
13 {
14 ((System.Windows.Forms.Timer)sender).Stop();
15 MessageBox.Show(time.ToString());
16 }
17 }
18
19 [StructLayout(LayoutKind.Sequential)]
20 struct LASTINPUTINFO
21 {
22 [MarshalAs(UnmanagedType.U4)]
23 public int cbSize;
24 [MarshalAs(UnmanagedType.U4)]
25 public uint dwTime;
26 }
27
28 [DllImport("user32.dll")]
29 static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
30
31 static long GetLastInputTime()
32 {
33 LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
34 vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
35 if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
36 return Environment.TickCount - (long)vLastInputInfo.dwTime;
37 }
相关文章推荐
- Windows用户自定义消息实现程序间通信
- php后台多用户权限组思路与实现程序代码分享
- java实现用户分页消息springmvc+mysql精装版本
- 应用挂起后接受jpush消息没有触发回调问题
- 你的微信小程序都没有社交属性,当然没有用户啦!
- BUG:Visual Studio 6.0 中出现错误消息“Setup Was Unable to Create a DCOM User Account”(安装程序无法创建 DCOM 用户帐户)
- 利用HttpModuler实现WEB程序同一时间只让一个用户实例登陆
- 若要调试此模块,请将其项目生成配置更改为“调试”模式。若要取消显示此消息,请禁用"启动时若没有用户代码则发出警告"调试器选项。
- BLOCK方式实现OC程序中多个页面判定用户是否登录
- 编写一个jsp程序,实现用户登录,当用户输入的用户或密码错误时,将页面重定向到错误提示页,并在该页面显示30秒后 自动回到用户登录界面
- php后台多用户权限组思路与实现程序代码
- VC++实现Vista和Win7系统低权限程序向高权限程序发消息
- 用Python实现的简洁版的用户登录程序
- Mailbox:六星期实现从零到百万用户及日处理亿条消息
- [置顶] 微信小程序模板消息的两种实现方式
- 编写一段Socket服务端程序,监听端口8888,接受到Client的消息“nihao”后,将“nihao”写回到客户端,关闭socket。
- 用APC实现在内核模式运行用户程序
- 利用HttpModuler实现WEB程序同一时间只让一个用户实例登陆
- [转]利用HttpModuler实现WEB程序同一时间只让一个用户实例登陆
- 用户登录程序实现