How long does PostMessage() take to send to HWND_BROADCAST?

60 Views Asked by At

I am using the standard winapi low-level keyboard hook mechanism in a small C program, which acts as an invisible server app. When the hook proc detects certain keystrokes it broadcasts a custom message to all my client apps which are listening for these alerts. It is all working well in dev.

My question is about using PostMessage() with HWND_BROADCAST inside the hook proc. When I use a low-level keyboard hook in my dotnet apps it gets silently unhooked after a few hours. I'm guessing this is because the dotnet garbage collector is doing a full GC at the wrong moment. So instead of trying to improve my dotnet code I have moved the hook entirely into a separate C program, which is working well in test.

But I don't want to go down this route, only to find that PostMessage() with HWND_BROADCAST is taking too long. Does anyone know how long PostMessage() takes to post a message to all top-level windows? And will this timing degrade if a system is fully loaded, with more app instances and top-level windows? I don't want to encounter the issue I had with dotnet apps where the hook proc takes too long and windows silently unhooks it.

Thanks,

1

There are 1 best solutions below

0
Jeaninez - MSFT On

According to Remy Lebeau's recommendations:

It doesn't take very long at all to post a message into a message queue. PostMessage() doesn't wait for the message to be broadcasted. And targeted messaging would be better and could be made more secure.