在我的项目,我需要一个应用程序锁(像windows一样锁定)。如果应用程序是空闲一段时间的应用程序应锁定即,将显示该应用程序的登录窗口。我如何在WPF C#应用程序中执行此操作?检查如果一个应用程序是空闲的时间段并锁定
7
A
回答
12
您可以使用这些功能
看到这个代码,您必须将计时器添加到您的形式,并设置this.timer1.Enabled = TRUE;
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 WindowsFormsApplication9
{
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
public partial class Form1 : Form
{
[DllImport("User32.dll")]
public static extern bool LockWorkStation();
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO Dummy);
[DllImport("Kernel32.dll")]
private static extern uint GetLastError();
public static uint GetIdleTime()
{
LASTINPUTINFO LastUserAction = new LASTINPUTINFO();
LastUserAction.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(LastUserAction);
GetLastInputInfo(ref LastUserAction);
return ((uint)Environment.TickCount - LastUserAction.dwTime);
}
public static long GetTickCount()
{
return Environment.TickCount;
}
public static long GetLastInputTime()
{
LASTINPUTINFO LastUserAction = new LASTINPUTINFO();
LastUserAction.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(LastUserAction);
if (!GetLastInputInfo(ref LastUserAction))
{
throw new Exception(GetLastError().ToString());
}
return LastUserAction.dwTime;
}
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (GetIdleTime() > 10000) //10 secs, Time to wait before locking
LockWorkStation();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
}
}
0
0
IMO接受的答案是不是因为这个方法好:
http://www.codeproject.com/Articles/30345/Application-Idle
CodeProject上的文章使用Windows消息,这将导致组件考虑该申请没有闲着,如
public enum ActivityMessages : int
{
/// <summary>
/// Cursor moved while within the nonclient area.
/// </summary>
WM_NCMOUSEMOVE = 0x00A0,
/// <summary>
/// Mouse left button pressed while the cursor was within the nonclient area.
/// </summary>
WM_NCLBUTTONDOWN = 0x00A1,
/// <summary>
/// Mouse left button released while the cursor was within the nonclient area.
/// </summary>
WM_NCLBUTTONUP = 0x00A2,
/// <summary>
相关问题
- 1. 在一段空闲时间后锁定android应用程序
- 2. 应用程序空闲超时 - 希望实现特定空闲时间间隔的自动锁定
- 3. 应用程序的空闲时间
- 4. WPF:应用程序空闲时间
- 5. 如何临时锁定android应用程序一段时间?
- 6. 如何检查应用程序是否空闲?
- 7. 应用程序在Android应用程序空闲时间
- 8. 注销应用程序,如果自动应用程序是闲置了一段时间
- 9. javamail空闲停止触发消息一段时间后添加,线程锁定
- 10. 如何检测程序何时空闲?
- 11. Android的自动应用程序重新启动,如果设备在主屏幕和空闲一段时间
- 12. 如何获得应用程序空闲时间?
- 13. 如何根据可用时间段和预定时间段查找空闲时间段?
- 14. Ruby检查一个线程是否“空闲”
- 15. 在我的iphone中实现空闲时间应用程序
- 16. 关闭空闲时间的应用程序
- 17. Adobe AIR应用程序的空闲时间
- 18. 锁定空单元格并解锁空闲单元格
- 19. 如何检测网络空闲时间?
- 20. 使用python检测空闲时间
- 21. 如何检测我的应用程序在c#中空闲?
- 22. 在Windows Mobile中微调应用程序空闲时间
- 23. 在WPF应用程序中获取不活动/空闲时间
- 24. 锁定空闲队列入队如果不为空
- 25. 检查,如果一个文本字段是一个特定值
- 26. 应用程序崩溃,如果它处于空闲状态
- 27. 是否有可能让空闲时间退出我的程序?
- 28. 如何检测用户闲置一段时间并在PHP中销毁会话?
- 29. 如何检查iOS中应用程序的可用空间?
- 30. iOS应用空闲然后锁
你知道如何实现MVC应用程序? – alice7 2012-06-19 21:16:42
此检测何时系统作为一个整体是空闲的,而不是当一个特定的应用程序处于空闲状态。 – 2015-06-04 16:32:17