Performance cost of SetWinEventHook vs Polling in c#?

这一生的挚爱 提交于 2021-02-10 06:15:41

问题


I am developing a time tracking application, it monitors window changes and user idleness. My question is: which one costs more in terms of performance, wasting system resources:

  • using SetWinEventHook (EVENT_SYSTEM_FOREGROUND),

  • or setting a Timer.Tick and check if the active window title changed user32.dll GetForegroundWindow() and GetWindowText() all the time) ?

For testing user idleness I already figured out that using low level mouse and keyboard hooks are more expensive than calling GetLastInputInfo() with a Timer. (or am I doing something wrong?) I used these sources for the keyboard and mouse hooks: https://blogs.msdn.microsoft.com/toub/2006/05/03/low-level-keyboard-hook-in-c/ and for the window change hooks: Detect active window changed using C# without polling

Thanks!

来源:https://stackoverflow.com/questions/41059514/performance-cost-of-setwineventhook-vs-polling-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!