using System;
using System.Collections.Generic;
using System.Text;

///¹¦ÄÜ£ºÊÂ¼þ´úÀí
///Íê³ÉÊ±¼ä£º2009-3-2
///×÷Õß£ºÒ»æÝ
///ÒÅÁôÎÊÌâ£ºÎÞ
///¿ª·¢¼Æ»®£ºÎÞ
///ËµÃ÷£ºÎÞ 
///°æ±¾£º01.10.00
///ÐÞ¶©£ºÎÞ
namespace SoukeyNetget.Gather
{
    internal class cEventProxy
    {
        internal cEventProxy()
        {
            m_EventList = new List<EventInvoke>();
        }

        internal delegate void EventInvoke();
        private List<EventInvoke> m_EventList;
        private readonly Object m_eventLock = new Object();

        /// <summary>
        /// Á¢¼´´¦ÀíËùÓÐ´úÀíÊÂ¼þ
        /// </summary>
        internal void DoEvents()
        {
            if (m_EventList.Count > 0)
            {
                EventInvoke[] events;
                lock (m_eventLock)
                {
                    events = m_EventList.ToArray();
                    m_EventList = new List<EventInvoke>();
                }
                if (events.Length > 0)
                {   // Ë«ÖØ¼ì²é
                    for (int i = 0; i < events.Length; i++)
                    {
                        events[i]();
                    }
                }
            }
        }
        /// <summary>
        /// Ìí¼ÓÊÂ¼þ´úÀí
        /// </summary>
        /// <param name="evt"></param>
        internal void AddEvent(EventInvoke evt)
        {
            lock (m_eventLock)
            {
                m_EventList.Add(evt);
            }
        }
    }
}
