问题
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