Beispiel #1
0
 protected EventListener()
 {
     lock (EventListener.EventListenersLock)
     {
         if (EventListener.s_CreatingListener)
         {
             throw new InvalidOperationException(Environment.GetResourceString("EventSource_ListenerCreatedInsideCallback"));
         }
         try
         {
             EventListener.s_CreatingListener = true;
             this.m_Next = EventListener.s_Listeners;
             EventListener.s_Listeners = this;
             foreach (WeakReference item_0 in EventListener.s_EventSources.ToArray())
             {
                 EventSource local_4 = item_0.Target as EventSource;
                 if (local_4 != null)
                 {
                     local_4.AddListener(this);
                 }
             }
         }
         finally
         {
             EventListener.s_CreatingListener = false;
         }
     }
 }
Beispiel #2
0
        // Token: 0x060033DF RID: 13279 RVA: 0x000C9344 File Offset: 0x000C7544
        internal static void AddEventSource(EventSource newEventSource)
        {
            object eventListenersLock = EventListener.EventListenersLock;

            lock (eventListenersLock)
            {
                if (EventListener.s_EventSources == null)
                {
                    EventListener.s_EventSources = new List <WeakReference>(2);
                }
                if (!EventListener.s_EventSourceShutdownRegistered)
                {
                    EventListener.s_EventSourceShutdownRegistered = true;
                    AppDomain.CurrentDomain.ProcessExit          += EventListener.DisposeOnShutdown;
                    AppDomain.CurrentDomain.DomainUnload         += EventListener.DisposeOnShutdown;
                }
                int num = -1;
                if (EventListener.s_EventSources.Count % 64 == 63)
                {
                    int num2 = EventListener.s_EventSources.Count;
                    while (0 < num2)
                    {
                        num2--;
                        WeakReference weakReference = EventListener.s_EventSources[num2];
                        if (!weakReference.IsAlive)
                        {
                            num = num2;
                            weakReference.Target = newEventSource;
                            break;
                        }
                    }
                }
                if (num < 0)
                {
                    num = EventListener.s_EventSources.Count;
                    EventListener.s_EventSources.Add(new WeakReference(newEventSource));
                }
                newEventSource.m_id = num;
                for (EventListener next = EventListener.s_Listeners; next != null; next = next.m_Next)
                {
                    newEventSource.AddListener(next);
                }
            }
        }
Beispiel #3
0
 internal static void AddEventSource(EventSource newEventSource)
 {
     lock (EventListener.EventListenersLock)
     {
         if (EventListener.s_EventSources == null)
         {
             EventListener.s_EventSources = new List <WeakReference>(2);
         }
         if (!EventListener.s_EventSourceShutdownRegistered)
         {
             EventListener.s_EventSourceShutdownRegistered = true;
             AppDomain.CurrentDomain.ProcessExit          += new EventHandler(EventListener.DisposeOnShutdown);
             AppDomain.CurrentDomain.DomainUnload         += new EventHandler(EventListener.DisposeOnShutdown);
         }
         int local_2 = -1;
         if (EventListener.s_EventSources.Count % 64 == 63)
         {
             int local_3 = EventListener.s_EventSources.Count;
             while (0 < local_3)
             {
                 --local_3;
                 WeakReference local_4 = EventListener.s_EventSources[local_3];
                 if (!local_4.IsAlive)
                 {
                     local_2        = local_3;
                     local_4.Target = (object)newEventSource;
                     break;
                 }
             }
         }
         if (local_2 < 0)
         {
             local_2 = EventListener.s_EventSources.Count;
             EventListener.s_EventSources.Add(new WeakReference((object)newEventSource));
         }
         newEventSource.m_id = local_2;
         for (EventListener local_5 = EventListener.s_Listeners; local_5 != null; local_5 = local_5.m_Next)
         {
             newEventSource.AddListener(local_5);
         }
     }
 }
        /// <summary>
        /// This routine adds newEventSource to the global list of eventSources, it also assigns the
        /// ID to the eventSource (which is simply the oridinal in the global list).
        /// 
        /// EventSources currently do not pro-actively remove themselves from this list. Instead
        /// when eventSources's are GCed, the weak handle in this list naturally gets nulled, and
        /// we will reuse the slot. Today this list never shrinks (but we do reuse entries
        /// that are in the list). This seems OK since the expectation is that EventSources
        /// tend to live for the lifetime of the appdomain anyway (they tend to be used in
        /// global variables).
        /// </summary>
        /// <param name="newEventSource"></param>
        internal static void AddEventSource(EventSource newEventSource)
        {
            lock (EventListenersLock)
            {
                if (s_EventSources == null)
                    s_EventSources = new List<WeakReference>(2);

                // Periodically search the list for existing entries to reuse, this avoids
                // unbounded memory use if we keep recycling eventSources (an unlikely thing). 
                int newIndex = -1;
                if (s_EventSources.Count % 64 == 63)   // on every block of 64, fill up the block before continuing
                {
                    int i = s_EventSources.Count;      // Work from the top down. 
                    while (0 < i)
                    {
                        --i;
                        WeakReference weakRef = s_EventSources[i];
                        if (!weakRef.IsAlive)
                        {
                            newIndex = i;
                            weakRef.Target = newEventSource;
                            break;
                        }
                    }
                }
                if (newIndex < 0)
                {
                    newIndex = s_EventSources.Count;
                    s_EventSources.Add(new WeakReference(newEventSource));
                }
                newEventSource.m_id = newIndex;

                // Add every existing dispatcher to the new EventSource
                for (EventListener listener = s_Listeners; listener != null; listener = listener.m_Next)
                    newEventSource.AddListener(listener);

                Validate();
            }
        }