Opc.Ua.Com.Server.ComAe2Subscription.SendInBlocks C# (CSharp) Method

SendInBlocks() private method

Sends the queued events in blocks.
private SendInBlocks ( IComAeEventCallback callback, Queue events, uint blockSize, bool refreshFlag ) : void
callback IComAeEventCallback
events Queue
blockSize uint
refreshFlag bool
return void
        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);
                    }
                }
            }
        }