コード例 #1
0
ファイル: EventCore.cs プロジェクト: VE-2016/VE-2016
        /// <summary>
        /// consumes events posted to the queue. decouples event processing from it's generation.
        /// </summary>
        private void EventConsumerTask()
        {
            // this will hold the dequeued event.
            CommonEventInfo info = null;

            // loop while the run flag is true
            while (_run)
            {
                // wait for a new item to be posted to the queue.
                _newEventEvent.WaitOne();

                // consume any items on the queue:
                while (_eventQueue.Count > 0)
                {
                    // syncrhonize access to the queue
                    lock (_eventQueueLocker)
                    {
                        // extract the item from the queue
                        info = _eventQueue.Dequeue();
                    }

                    // check we have an item
                    if (info != null)
                    {
                        // raise the event...this might take some time:
                        info.RaiseEvent();
                    }
                }
            }
        }
コード例 #2
0
ファイル: EventCore.cs プロジェクト: VE-2016/VE-2016
        /// <summary>
        /// public method used to raise the common-event. The event detail is added to a FIFO queue for processing by
        /// another thread.
        /// </summary>
        /// <param name="source">object raising the event</param>
        /// <param name="info">event-information of the event being raised</param>
        /// <param name="arguments">the arguments of the original event</param>
        public void SubmitEvent(object source, EventInfo info, params Object[] arguments)
        {
            // generate the event-info class:
            CommonEventInfo evi = new CommonEventInfo(source, this, info, arguments);

            // add that class to the queue:
            lock (_eventQueueLocker)
                _eventQueue.Enqueue(evi);

            // signal the auto-reset event that a new item was added to the queue.
            _newEventEvent.Set();
        }