本文整理汇总了C#中System.Diagnostics.Tracing.EventSource.AddListener方法的典型用法代码示例。如果您正苦于以下问题:C# EventSource.AddListener方法的具体用法?C# EventSource.AddListener怎么用?C# EventSource.AddListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Tracing.EventSource
的用法示例。
在下文中一共展示了EventSource.AddListener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddEventSource
/// <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();
}
}