Exemplo n.º 1
0
        /// <summary>
        /// Dequeues an event from the front of the event buffer while invoking the method.
        /// </summary>
        /// <returns>An InvocationTarget if there are further events, or null if
        /// there are no more events to process.</returns>
        public bool InvokeNext()
        {
            bool executed = false;

            lock (this)
            {
                iterating = true;

                if (events.Count > 0)
                {
                    Invocation invocation = events.Dequeue();
                    invocation.Invoke();
                    invocation.Dispose();
                    executed = true;
                }

                foreach (Invocation inv in waitBuffer)
                {
                    if (inv.Ready())
                    {
                        if (executed)
                        {
                            events.Enqueue(inv);
                        }
                        else
                        {
                            inv.Invoke();
                            inv.Dispose();
                            executed = true;
                        }
                    }
                }

                waitBuffer.RemoveAll((inv) => { return(inv.Ready()); });

                iterating = false;
                ManageIteratingBuffer();
            }

            return(executed);
        }