无法在 Windows 7 中使用 C# 中的窗口服务计算系统空闲值
我已经使用了提到的代码 这里通过窗口服务计算系统空闲时间。但在 Windows 7 和 Windows 7 中Vista 我总是将 LastInputInfo.dwTime
设为零,因此我无法计算系统空闲时间。我给出了下面的代码示例。
// If we have a value from the function
if (GetLastInputInfo(ref LastInputInfo))
{
// Get the number of ticks at the point when the last activity was seen
LastInputTicks = (int)LastInputInfo.dwTime;
// Number of idle ticks = system uptime ticks - number of ticks at last input
IdleTicks = systemUptime - LastInputTicks;
}
当我在 Windows 应用程序中测试相同的代码时,我得到了正确的 dwTime。我的服务中需要有正确的 dwTime 来计算系统的正确空闲时间。
请帮忙举一些例子
I have used the code mentioned here to calculate the system Idle time through a window service. But in windows 7 & Vista I always get the LastInputInfo.dwTime
as zero by which I cannot calculate the system idle time. I have given the code sample below.
// If we have a value from the function
if (GetLastInputInfo(ref LastInputInfo))
{
// Get the number of ticks at the point when the last activity was seen
LastInputTicks = (int)LastInputInfo.dwTime;
// Number of idle ticks = system uptime ticks - number of ticks at last input
IdleTicks = systemUptime - LastInputTicks;
}
When I test the same code in a windows application I get the correct dwTime
. I need to have the correct dwTime
in my service to calculate correct idle time of the system.
Please help with some examples
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您无法在 Windows 7 上的 Windows 服务中使用 GetLastInputInfo。这与代码无关,而是与 Vista 及更高版本中的服务强化有关。
阅读此内容:Windows Vista 和 Longhorn Server 的会话 0 中的服务隔离
I dont think you will be able to use GetLastInputInfo in windows service on Windows 7. This is not about the code, It's about service hardening in Vista and later.
Read this: Services isolation in Session 0 of Windows Vista and Longhorn Server