如何测量C#中的系统空闲时间,不包括看电影等?

如何测量C#中的系统空闲时间,不包括看电影等?,第1张

概述如何测量C#中的系统空闲时间,不包括看电影等?

我正在寻找一个在windows上测量系统空闲时间的程序。 我发现许多代码都是这样做的。 例如,

http://www.codeproject.com/KB/cs/GetIDleTimeWithCS.aspx

不过,我也想考虑用户看电影,录像等。那个时候没有给出input,但是系统仍然没有闲置。

有没有办法做到这一点?

仅在linux Core上运行时存储错误

当文件被locking时,稍后对文件 *** 作进行排队

我怎么能听监视器被添加或删除?

在windows中获取保留的文件名

如何检测SD卡何时插入?

如何恢复/降级windows Phone 8.1应用程序到C#5,我不小心升级到C#6

如何从C#中的打印机中删除访问控制条目?

如何远程启动不同系统上的应用程序?

单窗口的风格不同于系统的风格

如何防止显示“程序意外终止”窗口?

这个函数检测一个进程是否全屏运行在forground,如果找到了,返回进程的名字:

[Dllimport("user32.dll")] static extern IntPtr GetForegrounDWindow(); [Dllimport("user32.dll",SetLastError = true)] static extern bool GetwindowRect(IntPtr hWnd,out RECT lpRect); [Dllimport("user32.dll")] private static extern Int32 GetwindowThreadProcessID(IntPtr hWnd,out uint lpDWProcessID); [Dllimport("user32.dll")] private static extern bool GetwindowPlacement(IntPtr hWnd,ref WINDOWPLACEMENT lpwndpl); private struct POINTAPI { public int x; public int y; } private struct RECT { public int left; public int top; public int right; public int bottom; } private struct WINDOWPLACEMENT { public int length; public int flags; public int showCmd; public POINTAPI ptMinposition; public POINTAPI ptMaxposition; public RECT rcnormalposition; } public string FullscreenProcess() { IntPtr foreWindow = GetForegrounDWindow(); // get the placement WINDOWPLACEMENT forePlacement = new WINDOWPLACEMENT(); forePlacement.length = Marshal.SizeOf(forePlacement); GetwindowPlacement(foreWindow,ref forePlacement); if (forePlacement.rcnormalposition.top == 0 && forePlacement.rcnormalposition.left == 0 && forePlacement.rcnormalposition.right == Screen.PrimaryScreen.Bounds.WIDth && forePlacement.rcnormalposition.bottom == Screen.PrimaryScreen.Bounds.Height) { uint processID; GetwindowThreadProcessID(foreWindow,out processID); Process proc = Process.GetProcessByID((int)processID); return proc.Processname; } return null; }

在此之后,我们只需要将返回的进程名称与一组流行的媒体播放器或其他进程相匹配即可。

限制是我们假设用户在全屏播放。

您可以使用此计算机获得空闲时间,但是您的问题是如何知道电影正在播放的天气,您可以检查当前正在计算机上运行的进程System.Diagnostics.Process.GetProcesses() ,然后检查是否其中之一是一个已知的电影播放器​​。 但是我不认为这样做会实现你所锁定的内容,因为即使你发现一个Gom播放器正在运行,你仍然不知道它是运行视频还是音频,还是只是在没有任何东西的情况下打开打…

如果您以全屏观看视频:您可以使用这样的代码来确定是否有全屏应用程序运行:

[Dllimport("user32.dll")] static extern IntPtr GetForegrounDWindow(); [Dllimport("user32.dll",out RECT lpRect); [StructLayout(LayoutKind.Sequential)] struct RECT { public int left; public int top; public int WIDth; public int Height; } static bool IsBigWindowRunning() { foreach (Process proc in Process.GetProcesses()) { RECT rect; var success = GetwindowRect(proc.MainWindowHandle,out rect); if(success && (r.left + r.WIDth) >= Screen.PrimaryScreen.WorkingArea.WIDth) { return true; } } return false; }

我没有很好的测试,我会定义这个线路,增加一些限制:

if((r.left + r.WIDth) >= Screen.PrimaryScreen.WorkingArea.WIDth)

祝你好运!

总结

以上是内存溢出为你收集整理的如何测量C#中的系统空闲时间,不包括看电影等?全部内容,希望文章能够帮你解决如何测量C#中的系统空闲时间,不包括看电影等?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1276039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存