StatStore被State and Notifications Broker替换也有些年头了,StatStore也和State and Notifications Broker一样提供了注册表访问、上报键值改动的能力,以前也没体会出替换的必要性。但最近在维护一个旧程序时,发现对同一键值的修改,通过IStatStore::RegisterForNotifications和RegistryNotifyCallback上报延迟差异很大,IStatStore::RegisterForNotifications往往要要慢个2-3秒。
我猜想IStatStore很可能采用窗口消息来处理回调了,故通过反汇编验证一下。
以下是根据笔者反汇编所得,改用C/C++描述的CStatStore::RegisterForNotifications方法实现:
从上可知,CStatStore::RegisterForNotifications方法内调用了CreateWorkerWindow函数以创建一个Worker窗口,而且将CallbackInfo结构指针传给这个窗口。
我们再看窗口过程CStatStore::_WndProc的实现:
由上可知,当窗口过程收到WM_CREATE消息后,将CreateWorkerWindow传入的CallbackInfo结构复制并保存起来;当收到ID为0x401的消息后,将CallbackInfo结构取出,调用结构成员pfn所指的回调函数。
由此可见,StatStore依赖于窗口消息处理,对响应速度的影响极大。