private void SendInBlocks(IComAeEventCallback callback, Queue<AeEvent> events, uint blockSize, bool refreshFlag)
{
if (callback == null)
{
return;
}
if (blockSize == 0)
{
blockSize = (uint)events.Count;
}
while (events.Count > 0)
{
List<ONEVENTSTRUCT> eventsInBlock = new List<ONEVENTSTRUCT>();
try
{
for (int ii = 0; ii < blockSize && events.Count > 0; ii++)
{
// warning - Translate() allocates unmanaged memory that is deleted in the finally block.
eventsInBlock.Add(Translate(events.Dequeue()));
}
// invoke callback.
callback.OnEvent(
ClientHandle,
refreshFlag,
(refreshFlag)?events.Count == 0:false,
eventsInBlock.ToArray());
}
finally
{
// must deallocate attributes on exit.
for (int ii = 0; ii < eventsInBlock.Count; ii++)
{
IntPtr pAttributes = eventsInBlock[ii].pEventAttributes;
ComUtils.GetVARIANTs(ref pAttributes, eventsInBlock[ii].dwNumEventAttrs, true);
}
}
}
}