EvtSubscribe 拉式模型与推式模型
我正在尝试使用 Windows 中的以下 api。
EVT_HANDLE WINAPI EvtSubscribe(
__in EVT_HANDLE Session,
__in HANDLE SignalEvent,
__in LPCWSTR ChannelPath,
__in LPCWSTR Query,
__in EVT_HANDLE Bookmark,
__in PVOID context,
__in EVT_SUBSCRIBE_CALLBACK Callback,
__in DWORD Flags
);
此 API 支持两种订阅模式 PULL
和 PUSH
有两种订阅模型:拉取模型和推送模型。在推送模型中,您实现订阅回调并将 Callback 参数设置为您的实现。该服务将为每个符合您的查询条件(或发生错误)的事件调用您的回调。
在拉模型中,您创建一个由服务发出信号的事件对象。收到信号后,您可以使用订阅句柄调用 EvtNext 函数来枚举事件。您必须对枚举的每个事件调用 EvtClose 函数。然后,您重置该对象并等待服务再次发出信号。重复此过程,直到您取消订阅。
我想知道哪种模型可以扩展。以及选择一种模型相对于另一种模型的优点/缺点是什么。
I am trying to use following api from windows.
EVT_HANDLE WINAPI EvtSubscribe(
__in EVT_HANDLE Session,
__in HANDLE SignalEvent,
__in LPCWSTR ChannelPath,
__in LPCWSTR Query,
__in EVT_HANDLE Bookmark,
__in PVOID context,
__in EVT_SUBSCRIBE_CALLBACK Callback,
__in DWORD Flags
);
This api supports two models for subscription PULL
and PUSH
There are two subscription models: the pull model and the push model. In the push model, you implement a subscription callback and set the Callback parameter to your implementation. The service will call your callback for each event that matches your query criteria (or if an error occurs).
In the pull model, you create an event object that the service signals. When signaled, you call the EvtNext function using the subscription handle to enumerate the events. You must call the EvtClose function on each event that you enumerate. You then reset the object and wait for the service to signal again. This process repeats until you cancel the subscription.
I want to know which model will be scalable. and what are the pros/cons of choosing one model over another.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回调函数是从另一个线程调用的,因此您可能必须同步,如果必须同步,则使用拉取模型会更容易...如果同步,则使用事件关闭订阅会更容易,因为您可能会等待关于两个事件,一个来自 EvtSubscribe,另一个要关闭...
我花了几个小时来理解为什么我对 EvtClose 的调用会因回调模型而挂起!
Callback function is called from another thread, so you may have to synchronize, and if you have to synchronize it will be easier with the pull model... And if synchronize it will be easier to close the subscription with Event, as you may wait on two event, the one from EvtSubscribe and the one to close...
I waste some hours understanding why my call to EvtClose hangs with the callback model !
同意 Jean Davy 的
观点 Pull 方法将帮助您更轻松地处理多线程,因为本质上主线程将能够处理所有事情。它更简单。
Agree with Jean Davy
Pull method will help you in handling multithreading more easily as essentially the main thread will be able to handle everything. its simpler.